示例#1
0
    def login_from_snapshot(self, tag):
        """restore session from snapshot"""
        # check emulator
        if not self.emulator:
            raise EmulatorActionException('No emulator instance is specified')
        # check snapshot
        tags_in_use = [x['tag'] for x in self.emulator.list_snapshot()]
        if tag not in tags_in_use:
            raise EmulatorActionException(
                'No snapshot with tag {}'.format(tag))
        # try to load snapshot
        if not self.emulator.load_snapshot(tag):
            raise EmulatorActionException(
                'Fail to load snapshot {}'.format(tag))
        # try to restore appium session
        desired_caps = self.driver.capabilities
        desired_caps['autoLaunch'] = False
        try:
            self.driver = webdriver.Remote(self.driver.command_executor._url,
                                           desired_caps)
        except URLError:
            raise TestInitException('appium is not running')

        # try to login
        if self.idp == 'fb':
            status = 'IdpNeedLogin'
        return status
示例#2
0
    def clone(src, dst, timeout=120):
        """clone genymotion player"""

        # check src and dst emulators
        players_info = GenyPlayer._get_players_info()
        if src not in players_info:
            raise EmulatorActionException('source emulator does not exist')
        if dst in players_info:
            raise EmulatorActionException(
                'destination emulator already exists')

        cmd = "{} admin clone '{}' '{}'".format(GenyPlayer.gmtool, src, dst)
        BaseEmulator.command(cmd, timeout=timeout)
        return True
示例#3
0
 def delete_snapshot(self, tag):
     """wrapper to delete android emulator snapshot"""
     self._socket.send('avd snapshot del {}\n'.format(tag))
     res = self.recv_line()
     if 'KO' in res:
         raise EmulatorActionException(
             'Fail to delete snapshot {}\n{}'.format(tag, res))
     return True
示例#4
0
 def save_snapshot(self, tag):
     """wrapper to save android emulator snapshots"""
     self._socket.send('avd snapshot save {}\n'.format(tag))
     res = self.recv_line()
     if 'KO' in res:
         raise EmulatorActionException(
             'Fail to save snapshot {}'.format(tag))
     return True
示例#5
0
 def kill(self):
     """wrapper to kill emulator when adb errors"""
     self._socket.send('kill\n')
     res = self.recv_line()
     if 'KO' in res:
         raise EmulatorActionException(
             'Fail to kill emulator\n{}'.format(res))
     self.recv_until('OK\r\n')
     return True
示例#6
0
 def kill(self, timeout=60):
     """kill genymotion player"""
     if self._get_players_info()[self.device_name]['state'] != 'Off':
         if self.check_adb_status():
             self.adb_reboot()
         cmd = "{} admin stop '{}'".format(self.gmtool, self.device_name)
         self.command(cmd, timeout=timeout / 2)
         if self._get_players_info()[self.device_name]['state'] != 'Off':
             raise EmulatorActionException('Can not stop emulator')
         return True
     return True
示例#7
0
    def clone(src, dst, timeout=120):
        """clone emulator"""

        # src and dst check
        avd_path = os.path.join(os.environ['HOME'], '.android', 'avd')
        avd_src = os.path.join(avd_path, '{}.avd'.format(src))
        avd_dst = os.path.join(avd_path, '{}.avd'.format(dst))
        ini_src = os.path.join(avd_path, '{}.ini'.format(src))
        ini_dst = os.path.join(avd_path, '{}.ini'.format(dst))
        if not os.path.exists(avd_src):
            raise EmulatorActionException('source emulator does not exist')
        if os.path.exists(avd_dst):
            raise EmulatorActionException(
                'destination emulator already exists')

        # start cloning
        cmd = 'cp -r {} {}'.format(avd_src, avd_dst)
        BaseEmulator.command(cmd, timeout=timeout)
        os.system('cat {} | sed -e "s/\\/{}/\\/{}/" > {}'.format(
            ini_src, src, dst, ini_dst))

        # overwrite config file
        conf = os.path.join(avd_dst, 'config.ini')
        # bad implemetation of modify config file
        with open(conf, 'a+') as conf_fd:
            content = conf_fd.read()
            if 'hw.keyboard' not in content:
                conf_fd.write('hw.keyboard=yes\n')
            if 'hw.lcd.width' not in content:
                conf_fd.write('hw.lcd.width=1080\n')
            if 'hw.lcd.height' not in content:
                conf_fd.write('hw.lcd.height=1920\n')
            if 'hw.lcd.depth' not in content:
                conf_fd.write('hw.lcd.depth=16\n')
            if 'hw.lcd.density' not in content:
                conf_fd.write('hw.lcd.density=480\n')
            if 'disk.dataPartition.size' not in content:
                conf_fd.write('disk.dataPartition.size = 4g')
        return True
示例#8
0
 def command(cmd, timeout=120):
     """receive message with timeout"""
     tmp = TemporaryFile()
     proc = subprocess.Popen(cmd, shell=True, stdout=tmp, stderr=tmp)
     while timeout > 0:
         ret = proc.poll()
         if ret is not None:
             tmp.seek(0)
             if ret:
                 raise EmulatorActionException(tmp.read())
             return tmp.read()
         time.sleep(1)
         timeout -= 1
     proc.kill()
     raise EmulatorTimeoutException
示例#9
0
    def load_snapshot(self, tag, timeout=60):
        """wrapper to load android emulator snapshot"""
        def handler(signum, frame):
            """handler for handling alarm signal"""
            raise EmulatorActionException(
                'Fail to load snapshot {}\n{}'.format(tag, res))

        signal.signal(signal.SIGALRM, handler)
        signal.alarm(timeout)
        self._socket.send('avd snapshot load {}\n'.format(tag))
        res = self.recv_line()
        signal.alarm(0)
        if 'KO' in res:
            raise EmulatorActionException(
                'Fail to load snapshot {}\n{}'.format(tag, res))
        return True
示例#10
0
 def handler(signum, frame):
     """handler for handling alarm signal"""
     raise EmulatorActionException(
         'Fail to load snapshot {}\n{}'.format(tag, res))