Best Python code snippet using Airtest
apk.py
Source:apk.py
...72 Return the files inside the APK73 """74 return self.zip.namelist()75 files = property(get_files)76 def get_files_types(self):77 """78 Return the files inside the APK with their types (by using python-magic)79 """80 try:81 import magic82 except ImportError:83 return {}84 l = {}85 builtin_magic = 086 try:87 getattr(magic, "Magic")88 except AttributeError:89 builtin_magic = 190 if builtin_magic:91 ms = magic.open(magic.MAGIC_NONE)92 ms.load()93 for i in self.get_files():94 l[ i ] = ms.buffer(self.zip.read(i))95 else:96 m = magic.Magic()97 for i in self.get_files():98 l[ i ] = m.from_buffer(self.zip.read(i))99 return l100 files_types = property(get_files_types)101 def get_raw(self):102 """103 Return raw bytes of the APK104 """105 return self.__raw106 raw = property(get_raw)107 def get_file(self, filename):108 """109 Return the raw data of the specified filename110 """111 try:112 return self.zip.read(filename)113 except KeyError:114 return ""115 def get_dex(self):116 """117 Return the raw data of the classes dex file118 """119 return self.get_file("classes.dex")120 dex = property(get_dex)121 def get_elements(self, tag_name, attribute):122 """123 Return elements in xml files which match with the tag name and the specific attribute124 @param tag_name: a string which specify the tag name125 @param attribute: a string which specify the attribute126 """127 l = []128 for i in self.xml:129 for item in self.xml[i].getElementsByTagName(tag_name):130 value = item.getAttribute(attribute)131 if len(value) > 0:132 if value[0] == ".":133 value = self.package + value134 else:135 v_dot = value.find(".")136 if v_dot == 0:137 value = self.package + "." + value138 elif v_dot == -1:139 value = self.package + "." + value140 l.append(str(value))141 return l142 def get_element(self, tag_name, attribute):143 """144 Return element in xml files which match with the tag name and the specific attribute145 @param tag_name: a string which specify the tag name146 @param attribute: a string which specify the attribute147 """148 l = []149 for i in self.xml:150 for item in self.xml[i].getElementsByTagName(tag_name):151 value = item.getAttribute(attribute)152 if len(value) > 0:153 return value154 return None155 def get_activities(self):156 """157 Return the android:name attribute of all activities158 """159 return self.get_elements("activity", "android:name")160 activities = property(get_activities)161 def get_services(self):162 """163 Return the android:name attribute of all services164 """165 return self.get_elements("service", "android:name")166 services = property(get_services)167 def get_receivers(self):168 """169 Return the android:name attribute of all receivers170 """171 return self.get_elements("receiver", "android:name")172 receivers = property(get_receivers)173 def get_providers(self):174 """175 Return the android:name attribute of all providers176 """177 return self.get_elements("provider", "android:name")178 providers = property(get_providers)179 def get_permissions(self):180 """181 Return permissions182 """183 return self._permissions184 permissions = property(get_permissions)185 def get_min_sdk_version(self):186 """187 Return the android:minSdkVersion attribute188 """189 return self.get_element("uses-sdk", "android:minSdkVersion")190 min_sdk_version = property(get_min_sdk_version)191 def get_target_sdk_version(self):192 """193 Return the android:targetSdkVersion attribute194 """195 return self.get_element("uses-sdk", "android:targetSdkVersion")196 target_sdk_version = property(get_target_sdk_version)197 def get_libraries(self):198 """199 Return the android:name attributes for libraries200 """201 return self.get_elements("uses-library", "android:name")202 libraries = property(get_libraries)203 def show(self):204 print("FILES: ", self.get_files_types())205 print("ACTIVITIES: ", self.get_activities())206 print("SERVICES: ", self.get_services())207 print("RECEIVERS: ", self.get_receivers())...
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!!