How to use _transform_xy method in Airtest

Best Python code snippet using Airtest

ios.py

Source:ios.py Github

copy

Full Screen

...259 >>> touch((100, 100))260 >>> touch((0.5, 0.5), duration=1)261 """262 # trans pos of click, pos can be percentage or real coordinate263 x, y = self._transform_xy(pos)264 self.driver.click(x, y, duration)265 def double_click(self, pos):266 x, y = self._transform_xy(pos)267 self.driver.double_tap(x, y)268 def swipe(self, fpos, tpos, duration=0, *args, **kwargs):269 """270 Args:271 fpos: start point272 tpos: end point273 duration (float): start coordinate press duration (seconds), default is 0274 Returns:275 None276 Examples:277 >>> swipe((1050, 1900), (150, 1900))278 >>> swipe((0.2, 0.5), (0.8, 0.5))279 """280 fx, fy = self._transform_xy(fpos)281 tx, ty = self._transform_xy(tpos)282 self.driver.swipe(fx, fy, tx, ty, duration)283 def keyevent(self, keyname, **kwargs):284 """285 Perform keyevent on the device286 Args:287 keyname: home/volumeUp/volumeDown288 **kwargs:289 Returns:290 """291 try:292 keyname = KEY_EVENTS[keyname.lower()]293 except KeyError:294 raise ValueError("Invalid name: %s, should be one of ('home', 'volumeUp', 'volumeDown')" % keyname)295 else:296 self.press(keyname)297 298 def press(self, keys):299 """some keys in ["home", "volumeUp", "volumeDown"] can be pressed"""300 self.driver.press(keys)301 def text(self, text, enter=True):302 """303 Input text on the device304 Args:305 text: text to input306 enter: True if you need to enter a newline at the end307 Returns:308 None309 Examples:310 >>> text("test")311 >>> text("中文")312 """313 if enter:314 text += '\n'315 self.driver.send_keys(text)316 def install_app(self, uri, package):317 """318 curl -X POST $JSON_HEADER \319 -d "{\"desiredCapabilities\":{\"bundleId\":\"com.apple.mobilesafari\", \"app\":\"[host_path]/magicapp.app\"}}" \320 $DEVICE_URL/session321 https://github.com/facebook/WebDriverAgent/wiki/Queries322 """323 raise NotImplementedError324 def start_app(self, package, *args):325 """326 Args:327 package: the app bundle id, e.g ``com.apple.mobilesafari``328 Returns:329 None330 Examples:331 >>> start_app('com.apple.mobilesafari')332 """333 self.driver.app_launch(bundle_id=package)334 def stop_app(self, package):335 """336 Args:337 package: the app bundle id, e.g ``com.apple.mobilesafari``338 Returns:339 """340 self.driver.app_stop(bundle_id=package)341 342 def app_state(self, package):343 """344 Args:345 package:346 Returns:347 {348 "value": 4,349 "sessionId": "0363BDC5-4335-47ED-A54E-F7CCB65C6A65"350 }351 value 1(not running) 2(running in background) 3(running in foreground)? 4(running)352 Examples:353 >>> dev = device()354 >>> start_app('com.apple.mobilesafari')355 >>> print(dev.app_state('com.apple.mobilesafari')["value"]) # --> output is 4356 >>> home()357 >>> print(dev.app_state('com.apple.mobilesafari')["value"]) # --> output is 3358 >>> stop_app('com.apple.mobilesafari')359 >>> print(dev.app_state('com.apple.mobilesafari')["value"]) # --> output is 1360 """361 # output {"value": 4, "sessionId": "xxxxxx"}362 # different value means 1: die, 2: background, 4: running363 return self.driver.app_state(bundle_id=package)364 365 def app_current(self):366 """367 get the app current 368 Notes:369 Might not work on all devices370 Returns:371 current app state dict, eg:372 {"pid": 1281,373 "name": "",374 "bundleId": "com.netease.cloudmusic"}375 """376 return self.driver.app_current()377 def get_ip_address(self):378 """379 get ip address from webDriverAgent380 Returns:381 raise if no IP address has been found, otherwise return the IP address382 """383 return self.driver.status()['ios']['ip']384 def device_status(self):385 """386 show status return by webDriverAgent387 Return dicts of infos388 """389 return self.driver.status()390 def _touch_point_by_orientation(self, tuple_xy):391 """392 Convert image coordinates to physical display coordinates, the arbitrary point (origin) is upper left corner393 of the device physical display394 Args:395 tuple_xy: image coordinates (x, y)396 Returns:397 """398 x, y = tuple_xy399 # 部分设备如ipad,在横屏+桌面的情况下,点击坐标依然需要按照竖屏坐标额外做一次旋转处理400 if self.is_pad and self.orientation != wda.PORTRAIT:401 if not self.home_interface():402 return x, y403 width = self.display_info["width"]404 height = self.display_info["height"]405 if self.orientation in [wda.LANDSCAPE, wda.LANDSCAPE_RIGHT]:406 width, height = height, width407 if x < 1 and y < 1:408 x = x * width409 y = y * height410 x, y = XYTransformer.up_2_ori(411 (x, y),412 (width, height),413 self.orientation414 )415 return x, y416 def _transform_xy(self, pos):417 x, y = self._touch_point_by_orientation(pos)418 # scale touch postion419 if not (x < 1 and y < 1):420 x, y = int(x * self.touch_factor), int(y * self.touch_factor)421 return x, y422 def _check_orientation_change(self):423 pass424 def is_locked(self):425 """426 Return True or False whether the device is locked or not427 Notes:428 Might not work on some devices429 Returns:430 True or False...

Full Screen

Full Screen

graphix_dc.py

Source:graphix_dc.py Github

copy

Full Screen

...260 for x,y in ((0,0), (dx,0), (dx,dy), (0,dy))261 ]262 me.context.SetBrush( wx.Brush( wx.NamedColour('RED')))263 me.context.DrawPolygon( pts)264 p = me._transform_xy( 0, 0)265 q = me._transform_xy( dx, 0)266 from math import atan2, pi267 pangle = -180/pi * atan2( q[1]-p[1], q[0]-p[0])268 if 0:269 base_y = scaled_point_size - base_y + descent270 #print base_y271 #base_y -= 1 #??? закръглението требе да се обърне:-0.5 ЗА НЯКОИ неща ???272 matr.translate( 0, base_y, pre=True)273 p = me._transform_xy_int( 0,0)274 me.context.DrawRotatedText( txt, p[0], p[1], pangle)275 me.PopState()276 def _transform_xy( me, x, y, matrix =None):277 m = matrix or me.state.matrix278 return m.transform_xy( x,y)279 def _transform_xy_int( me, x, y, matrix =None):280 return [ to_int(c) for c in me._transform_xy( x,y, matrix) ]281if __name__ == '__main__':282 import unittest283 class TestDC( unittest.TestCase):284 def setUp( me):285 buff = wx.EmptyBitmap( 500,500)286 buff_dc = wx.MemoryDC( buff)287 me.context = GraphicsDC( buff_dc)288 def test_state_stack( me):289 depth = 10290 for i in range( 1, depth):291 me.assertEqual( i, len( me.context._state_stack), 'pushing')292 me.context.PushState()293 for i in range( depth, 1, -1):294 me.assertEqual( i, len( me.context._state_stack))#, 'poping')...

Full Screen

Full Screen

transform.py

Source:transform.py Github

copy

Full Screen

...172 def invalidate(self):173 print "I don't feel validated! (%s)" % (self.pass_through)174 return Transform.invalidate(self)175 176 def _transform_xy(self, n):177 #win_wd, win_ht = self.fitsimage.get_window_size()178 win_x, win_y = self.fitsimage.get_canvas_xy(n[0], n[1])179 #return float(win_x) / win_wd, float(win_y) / win_ht180 return (win_x, win_y)181 182 def transform_non_affine(self, xy):183 """184 Override the transform_non_affine method to implement the custom 185 transform.186 The input and output are Nx2 numpy arrays.187 """188 #print "transform in:", xy189 if self.fitsimage == None:190 return xy191 res = np.array(map(self._transform_xy, xy))192 #print "transform out:", res193 return res194 # This is where things get interesting. With this projection,195 # straight lines in data space become curves in display space.196 # This is done by interpolating new values between the input197 # values of the data. Since ``transform`` must not return a198 # differently-sized array, any transform that requires199 # changing the length of the data array must happen within200 # ``transform_path``.201 def transform_path_non_affine(self, path):202 ipath = path.interpolated(path._interpolation_steps)203 return Path(self.transform(ipath.vertices), ipath.codes)204 transform_path_non_affine.__doc__ = \205 Transform.transform_path_non_affine.__doc__206 if matplotlib.__version__ < '1.2':207 # Note: For compatibility with matplotlib v1.1 and older, you'll208 # need to explicitly implement a ``transform`` method as well.209 # Otherwise a ``NotImplementedError`` will be raised. This isn't210 # necessary for v1.2 and newer, however. 211 transform = transform_non_affine212 # Similarly, we need to explicitly override ``transform_path`` if213 # compatibility with older matplotlib versions is needed. With v1.2214 # and newer, only overriding the ``transform_path_non_affine``215 # method is sufficient.216 transform_path = transform_path_non_affine217 transform_path.__doc__ = Transform.transform_path.__doc__218 def inverted(self):219 tform = GingaAxes.InvertedGingaTransform()220 tform.fitsimage = self.fitsimage221 return tform222 223 inverted.__doc__ = Transform.inverted.__doc__224 class InvertedGingaTransform(Transform):225 input_dims = 2226 output_dims = 2227 is_separable = False228 fitsimage = None229 def _transform_xy(self, n):230 return self.fitsimage.get_data_xy(n[0], n[1])231 232 def transform_non_affine(self, xy):233 #print "transform in:", xy234 if self.fitsimage == None:235 return xy236 res = np.array(map(self._transform_xy, xy))237 #print "transform out:", res238 return res239 transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__240 # As before, we need to implement the "transform" method for 241 # compatibility with matplotlib v1.1 and older.242 if matplotlib.__version__ < '1.2':243 transform = transform_non_affine...

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