def restart_wda_proxy(self): if self._wda_proxy_proc: self._wda_proxy_proc.terminate() self._wda_proxy_port = freeport.get() self._wda_proxy_proc = subprocess.Popen([ "node", "wdaproxy.js", "-p", str(self._wda_proxy_port), "--wda-url", "http://localhost:{}".format(self._wda_port), "--mjpeg-url", "http://localhost:{}".format(self._mjpeg_port)]) # yapf: disable
async def run_webdriveragent(self) -> bool: """ UDID=$(idevice_id -l) UDID=${UDID:?} xcodebuild -project WebDriverAgent.xcodeproj \ -scheme WebDriverAgentRunner WebDriverAgentRunner id=$(idevice_id -l) test Raises: RuntimeError """ if self._procs: self.destroy() # hotfix #raise RuntimeError("should call destroy before run_webdriveragent", self._procs) async with self._lock: # holding lock, because multi wda run will raise error # Testing failed: # WebDriverAgentRunner-Runner.app encountered an error (Failed to install or launch the test # runner. (Underlying error: Only directories may be uploaded. Please try again with a directory # containing items to upload to the application_s sandbox.)) cmd = [ 'xcodebuild', '-project', os.path.join(self.wda_directory, 'WebDriverAgent.xcodeproj'), '-scheme', 'WebDriverAgentRunner', "-destination", 'id=' + self.udid, 'test' ] if os.getenv("TMQ") == "true": cmd = ['tins', '-u', self.udid, 'xctest'] self.run_background( cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) # cwd='Appium-WebDriverAgent') self._wda_port = freeport.get() self._mjpeg_port = freeport.get() self.run_background( ["./iproxy.sh", str(self._wda_port), "8100", self.udid], silent=True) self.run_background( ["./iproxy.sh", str(self._mjpeg_port), "9100", self.udid], silent=True) self.restart_wda_proxy() return await self.wait_until_ready()
async def proxy_device_port(self, device_port: int) -> int: """ reverse-proxy device:port to *:port """ local_port = await self.adb_forward_to_any("tcp:"+str(device_port)) listen_port = freeport.get() logger.debug("%s tcpproxy.js start *:%d -> %d", self, listen_port, local_port) self.run_background(['node', 'tcpproxy.js', str(listen_port), 'localhost', str(local_port)], silent=True) return listen_port
def restart_wda_proxy(self): if self._wda_proxy_proc: self._wda_proxy_proc.terminate() self._wda_proxy_port = freeport.get() logger.debug("restart wdaproxy with port: %d", self._wda_proxy_port) self._wda_proxy_proc = subprocess.Popen([ "node", "wdaproxy.js", "-p", str(self._wda_proxy_port), "--wda-url", "http://localhost:{}".format(self._wda_port), "--mjpeg-url", "http://localhost:{}".format(self._mjpeg_port)], stdout=subprocess.DEVNULL) # yapf: disable
async def adb_forward_to_any(self, remote: str) -> int: """ FIXME(ssx): not finished yet """ # if already forwarded, just return async for f in adb.forward_list(): if f.serial == self._serial: if f.remote == remote and f.local.startswith("tcp:"): return int(f.local[4:]) local_port = freeport.get() await adb.forward(self._serial, 'tcp:{}'.format(local_port), remote) return local_port
async def _init_forwards(self): logger.debug("%s forward atx-agent", self) self._atx_proxy_port = await self.proxy_device_port(7912) self._whatsinput_port = await self.proxy_device_port(6677) port = self._adb_remote_port = freeport.get() logger.debug("%s adbkit start, port %d", self, port) self.run_background([ 'node', 'node_modules/adbkit/bin/adbkit', 'usb-device-to-tcp', '-p', str(self._adb_remote_port), self._serial], silent=True)
async def run_webdriveragent(self) -> bool: """ UDID=$(idevice_id -l) UDID=${UDID:?} xcodebuild -project WebDriverAgent.xcodeproj \ -scheme WebDriverAgentRunner WebDriverAgentRunner id=$(idevice_id -l) test Raises: RuntimeError """ if self._procs: self.destroy() # hotfix #raise RuntimeError("should call destroy before run_webdriveragent", self._procs) async with self._lock: # holding lock, because multi wda run will raise error # Testing failed: # WebDriverAgentRunner-Runner.app encountered an error (Failed to install or launch the test # runner. (Underlying error: Only directories may be uploaded. Please try again with a directory # containing items to upload to the application_s sandbox.)) self._wda_port = freeport.get() self._mjpeg_port = freeport.get() cmd = [ 'xcodebuild', '-project', os.path.join(self.wda_directory, 'WebDriverAgent.xcodeproj'), '-scheme', 'WebDriverAgentRunner', "-destination", 'id=' + self.udid, 'test' ] if "Simulator" in self.product: # 模拟器 cmd.extend([ 'USE_PORT=' + str(self._wda_port), 'MJPEG_SERVER_PORT=' + str(self._mjpeg_port), ]) if os.getenv("TMQ") == "true": cmd = ['tins', '-u', self.udid, 'xctest'] if self.manually_start_wda: logger.info( "Got param --manually-start-wda , will not launch wda process" ) elif self.use_tidevice: # 明确使用 tidevice 命令启动 wda logger.info( "Got param --use-tidevice , use tidevice to launch wda") tidevice_cmd = [ 'tidevice', '-u', self.udid, 'xctest', '-B', self.wda_bundle_pattern ] self.run_background(tidevice_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) else: self.run_background( cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) # cwd='Appium-WebDriverAgent') if "Simulator" not in self.product: self.run_background([ "tidevice", '-u', self.udid, 'relay', str(self._wda_port), "8100" ], silent=True) self.run_background([ "tidevice", '-u', self.udid, 'relay', str(self._mjpeg_port), "9100" ], silent=True) self.restart_wda_proxy() return await self.wait_until_ready()