How to use builtin_iproxy_path method in Airtest

Best Python code snippet using Airtest

instruct_cmd.py

Source:instruct_cmd.py Github

copy

Full Screen

...30 self._device = None31 self.cleanup_handler = []32 reg_cleanup(self.tear_down)33 @staticmethod34 def builtin_iproxy_path():35 # Port forwarding for iOS:36 # 1. Windows/Mac: iproxy.exe/iproxy -u uid port1 port237 # 2. Ubuntu linux: apt-get install libusbmuxd-tools; iproxy port1 port238 # 3. Use python (low efficiency): python relay.py -t 5100:510039 if shutil.which("iproxy"):40 return shutil.which("iproxy")41 system = platform.system()42 iproxy_path = DEFAULT_IPROXY_PATH.get(system)43 if iproxy_path:44 if system == "Darwin":45 make_file_executable(iproxy_path)46 return iproxy_path47 warnings.warn("Please install iproxy for a better experience(Ubuntu Linux): apt-get install libusbmuxd-tools")48 return None49 @property50 def usb_device(self):51 """52 Whether the current iOS uses the local USB interface, if so, return the wda.usbmux.Device object53 当前iOS是否使用了本地USB接口,如果是,返回wda.usbmux.Device对象54 Returns: wda.usbmux.Device or None55 """56 if not self._device:57 # wda无法直接获取iOS的udid,因此先检查usb连接的手机udid列表58 for dev in wda.usbmux.Usbmux().device_list():59 udid = dev.get('SerialNumber')60 usb_dev = wda.Client(url=wda.requests_usbmux.DEFAULT_SCHEME + udid)61 # 对比wda.info获取到的uuid是否一致62 try:63 if usb_dev.info['uuid'] == self.uuid:64 self._device = wda.usbmux.Device(udid)65 self._udid = udid66 except:67 return None68 return self._device69 def tear_down(self):70 for func in self.cleanup_handler:71 func()72 self.cleanup_handler = []73 # this function auto gen local port74 @retries(3)75 def setup_proxy(self, device_port):76 local_port = random.randint(11111, 20000)77 self.do_proxy(local_port, device_port)78 return local_port, device_port79 def do_proxy(self, local_port, device_port):80 """81 Start do proxy of ios device and self device82 目前只支持本地USB连接的手机进行端口转发,远程手机暂时不支持83 Returns:84 None85 """86 if not self.usb_device:87 raise AirtestError("Currently only supports port forwarding for locally connected iOS devices")88 proxy_process = self.builtin_iproxy_path() or shutil.which("tidevice")89 if proxy_process:90 cmds = [proxy_process, "-u", self._udid, str(local_port), str(device_port)]91 else:92 # Port forwarding using python93 self.do_proxy_usbmux(local_port, device_port)94 return95 # Port forwarding using iproxy96 # e.g. cmds=['/usr/local/bin/iproxy', '-u', '00008020-001270842E88002E', '11565', '5001']97 proc = subprocess.Popen(98 cmds,99 stdin=subprocess.PIPE,100 stdout=subprocess.PIPE,101 stderr=subprocess.PIPE,102 creationflags=SUBPROCESS_FLAG...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful