Best Python code snippet using Airtest
ios.py
Source:ios.py
...165 return screen166 @retry_session167 def touch(self, pos, duration=0.01):168 # trans pos of click169 pos = self._touch_point_by_orientation(pos)170 # scale touch postion171 x, y = pos[0] * self._touch_factor, pos[1] * self._touch_factor172 if duration >= 0.5:173 self.session.tap_hold(x, y, duration)174 else:175 self.session.tap(x, y)176 def double_click(self, pos):177 # trans pos of click178 pos = self._touch_point_by_orientation(pos)179 x, y = pos[0] * self._touch_factor, pos[1] * self._touch_factor180 self.session.double_tap(x, y)181 def swipe(self, fpos, tpos, duration=0.5, steps=5, fingers=1):182 # trans pos of swipe183 fx, fy = self._touch_point_by_orientation(fpos)184 tx, ty = self._touch_point_by_orientation(tpos)185 self.session.swipe(fx * self._touch_factor, fy * self._touch_factor,186 tx * self._touch_factor, ty * self._touch_factor, duration)187 def keyevent(self, keys):188 """just use as home event"""189 if keys not in ['HOME', 'home', 'Home']:190 raise NotImplementedError191 self.home()192 @retry_session193 def text(self, text, enter=True):194 """bug in wda for now"""195 if enter:196 text += '\n'197 self.session.send_keys(text)198 def install_app(self, uri, package):199 """200 curl -X POST $JSON_HEADER \201 -d "{\"desiredCapabilities\":{\"bundleId\":\"com.apple.mobilesafari\", \"app\":\"[host_path]/magicapp.app\"}}" \202 $DEVICE_URL/session203 https://github.com/facebook/WebDriverAgent/wiki/Queries204 """205 raise NotImplementedError206 def start_app(self, package, activity=None):207 self.defaultSession = None208 self.driver.session(package)209 def stop_app(self, package):210 self.driver.session().close()211 def get_ip_address(self):212 """213 get ip address from webDriverAgent214 Returns:215 raise if no IP address has been found, otherwise return the IP address216 """217 return self.driver.status()['ios']['ip']218 def device_status(self):219 """220 show status return by webDriverAgent221 Return dicts of infos222 """223 return self.driver.status()224 def _touch_point_by_orientation(self, tuple_xy):225 """226 Convert image coordinates to physical display coordinates, the arbitrary point (origin) is upper left corner227 of the device physical display228 Args:229 tuple_xy: image coordinates (x, y)230 Returns:231 """232 x, y = tuple_xy233 # use correct w and h due to now orientation234 # _size åªå¯¹åºç«ç´æ¶åé¿å®½235 now_orientation = self.orientation236 if now_orientation in [PORTRAIT, PORTRAIT_UPSIDEDOWN]:237 width, height = self._size['width'], self._size["height"]238 else:...
input.py
Source:input.py
...9 self.device = dev10 self.adb = self.device.adb11 self.minitouch = Minitouch(self.device)12 def click(self, pos, duration=0.05, button='left'):13 pos = self._touch_point_by_orientation(pos)14 self.minitouch.touch(pos, duration=duration)15 def swipe(self, p1, p2, duration=0.5, steps=5, fingers=1, button='left'):16 p1 = self._touch_point_by_orientation(p1)17 p2 = self._touch_point_by_orientation(p2)18 if fingers == 1:19 self.minitouch.swipe(p1, p2, duration=duration, steps=steps)20 elif fingers == 2:21 self.minitouch.two_finger_swipe(22 p1, p2, duration=duration, steps=steps)23 else:24 raise Exception("param fingers should be 1 or 2")25 def pinch(self, *args, **kwargs):26 return self.minitouch.pinch(*args, **kwargs)27 def double_tap(self, pos, button='left'):28 duration = 0.0529 pos = self._touch_point_by_orientation(pos)30 self.minitouch.touch(pos, duration=duration)31 time.sleep(0.05)32 pos = self._touch_point_by_orientation(pos)33 self.minitouch.touch(pos, duration=duration)34 def is_keyboard_shown(self):35 return self.adb.is_keyboard_shown()36 def _touch_point_by_orientation(self, tuple_xy):37 x, y = tuple_xy38 x, y = XYTransformer.up_2_ori(39 (x, y),40 (self.device.screen.display_info["width"],41 self.device.screen.display_info["height"]),42 self.device.screen.display_info["orientation"]43 )44 return x, y45 @property46 def name(self):47 return self._name48 49 @name.setter50 def name(self, value):...
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!!