Best Python code snippet using Airtest
adb.py
Source:adb.py
...21 """adb object class"""22 def __init__(self, device_id: str = None, adb_path: str = None, host='127.0.0.1', port=5037):23 self.device_id = device_id24 self.adb_path = adb_path or self.builtin_adb_path()25 self._set_cmd_options(host, port)26 self.connect()27 self._event_path = None # eventä¿¡æ¯28 self._display_info = {}29 self._line_breaker = None30 # æªå¾æ件åå31 self._cap_name = ADB_CAP_NAME_RAW.format(self.get_device_id(decode=True))32 # æªå¾å¨ææºä¸çè·¯å¾33 self._cap_local_path = ADB_CAP_LOCAL_PATH.format(self._cap_name)34 # æªå¾pngåæ¾å°å·¥ç¨çè·¯å¾35 self._cap_remote_path = ADB_CAP_REMOTE_PATH.format(self.get_device_id(decode=True))36 # raw临æ¶æ件åæ¾å°å·¥ç¨çè·¯å¾37 self._cap_raw_remote_path = ADB_CAP_REMOTE_RAW_PATH.format(self._cap_name)38 # å·²ç»ä½¿ç¨ç端å£39 self._sdk_version = self.sdk_version()40 @staticmethod41 def builtin_adb_path() -> str:42 """adbè·¯å¾"""43 system = platform.system()44 machine = platform.machine()45 adb_path = DEFAULT_ADB_PATH.get('{}-{}'.format(system, machine))46 if not adb_path:47 adb_path = DEFAULT_ADB_PATH.get(system)48 if not adb_path:49 raise RuntimeError("No adb executable supports this platform({}-{}).".format(system, machine))50 # overwrite uiautomator adb51 if "ANDROID_HOME" in os.environ:52 del os.environ["ANDROID_HOME"]53 return adb_path54 def _set_cmd_options(self, host: str, port: int):55 """56 设置adbæå¡å¨57 Args:58 host: adbè·¯å¾59 port: adb端å£å·60 Returns:61 None62 """63 self.host = host64 self.port = port65 self.cmd_options = [self.adb_path]66 if self.host not in ("localhost", "127.0.0.1"):67 self.cmd_options += ['-H', self.host]68 if self.port != 5037:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!