(self, device=None, using_proxy=True, force_restart=False, use_airtest_input=False, **options)
| 141 | """ |
| 142 | |
| 143 | def __init__(self, device=None, using_proxy=True, force_restart=False, use_airtest_input=False, **options): |
| 144 | # 加这个参数为了不在最新的pocounit方案中每步都截图 |
| 145 | self.screenshot_each_action = True |
| 146 | if options.get('screenshot_each_action') is False: |
| 147 | self.screenshot_each_action = False |
| 148 | |
| 149 | self.device = device or default_device() |
| 150 | |
| 151 | self.adb_client = self.device.adb |
| 152 | if using_proxy: |
| 153 | self.device_ip = self.adb_client.host or "127.0.0.1" |
| 154 | else: |
| 155 | self.device_ip = self.device.get_ip_address() |
| 156 | |
| 157 | # save current top activity (@nullable) |
| 158 | try: |
| 159 | current_top_activity_package = self.device.get_top_activity_name() |
| 160 | except AirtestError as e: |
| 161 | # 在一些极端情况下,可能获取不到top activity的信息 |
| 162 | print(e) |
| 163 | current_top_activity_package = None |
| 164 | if current_top_activity_package is not None: |
| 165 | current_top_activity_package = current_top_activity_package.split('/')[0] |
| 166 | |
| 167 | # install ime |
| 168 | self.ime = YosemiteIme(self.adb_client) |
| 169 | |
| 170 | # install |
| 171 | self._instrument_proc = None |
| 172 | self._install_service() |
| 173 | |
| 174 | # forward |
| 175 | self.forward_list = [] |
| 176 | if using_proxy: |
| 177 | p0, _ = self.adb_client.setup_forward("tcp:10080") |
| 178 | p1, _ = self.adb_client.setup_forward("tcp:10081") |
| 179 | self.forward_list.extend(["tcp:%s" % p0, "tcp:%s" % p1]) |
| 180 | else: |
| 181 | p0 = 10080 |
| 182 | p1 = 10081 |
| 183 | |
| 184 | # start |
| 185 | ready = self._start_instrument(p0, force_restart=force_restart) |
| 186 | if not ready: |
| 187 | # 之前启动失败就卸载重装,现在改为尝试kill进程或卸载uiautomator |
| 188 | self._kill_uiautomator() |
| 189 | ready = self._start_instrument(p0) |
| 190 | |
| 191 | if current_top_activity_package is not None: |
| 192 | current_top_activity2 = self.device.get_top_activity_name() |
| 193 | if current_top_activity2 is None or current_top_activity_package not in current_top_activity2: |
| 194 | self.device.start_app(current_top_activity_package, activity=True) |
| 195 | |
| 196 | if not ready: |
| 197 | raise RuntimeError("unable to launch AndroidUiautomationPoco") |
| 198 | if ready: |
| 199 | # 首次启动成功后,在后台线程里监控这个进程的状态,保持让它不退出 |
| 200 | self._keep_running_thread = KeepRunningInstrumentationThread(self, p0) |
nothing calls this directly
no test coverage detected