How to use _search_for_current_package method in Airtest

Best Python code snippet using Airtest

adb.py

Source:adb.py Github

copy

Full Screen

...1186 """1187 output = self.shell("dumpsys window windows")1188 windows = output.split("Window #")1189 offsetx, offsety, x, y = info['width'], info['height'], 0, 01190 package = self._search_for_current_package(output)1191 for w in windows:1192 if "package=%s" % package in w:1193 arr = re.findall(r'Frames: containing=\[(\d+\.?\d*),(\d+\.?\d*)]\[(\d+\.?\d*),(\d+\.?\d*)]', w)1194 if len(arr) >= 1 and len(arr[0]) == 4:1195 offsetx, offsety, x, y = float(arr[0][0]), float(arr[0][1]), float(arr[0][2]), float(arr[0][3])1196 if info["orientation"] in [1, 3]:1197 offsetx, offsety, x, y = offsety, offsetx, y, x1198 x, y = x - offsetx, y - offsety1199 return {1200 "offset_x": offsetx,1201 "offset_y": offsety,1202 "offset_width": x,1203 "offset_height": y1204 }1205 def _search_for_current_package(self, ret):1206 """1207 Search for current app package name from the output of command "adb shell dumpsys window windows"1208 Returns:1209 package name if exists else ""1210 """1211 packageRE = re.compile('\s*mCurrentFocus=Window{.* ([A-Za-z0-9_.]+)/[A-Za-z0-9_.]+}')1212 m = packageRE.findall(ret)1213 if m:1214 return m[-1]1215 return ""1216def cleanup_adb_forward():1217 for adb in ADB._instances:1218 adb._cleanup_forwards()1219reg_cleanup(cleanup_adb_forward)

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