How to use _is_ios method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

air_appium.py

Source:air_appium.py Github

copy

Full Screen

...220 element.send_keys(text)221 except Exception as e:222 raise Exception('Cannot input text "%s" for the %s element "%s"' % (text, class_name, index_or_name))223 def home(self):224 if self._is_ios():225 return self.driver.press_button("home")226 elif self._is_android():227 return self.driver.press_keycode(3)228 else:229 raise Exception('Unsupport this keyword')230 def snapshot(self, filename=None, strType=False, quality=10, max_size=None, **kwargs):231 if self._is_ios() or self._is_android():232 value = self.driver.get_screenshot_as_base64()233 data = base64.b64decode(value)234 if strType:235 if filename:236 with open(filename, 'wb') as f:237 f.write(data)238 return data239 # output cv2 object240 try:241 screen = aircv.utils.string_2_img(data)242 except:243 # may be black/locked screen or other reason, print exc for debugging244 traceback.print_exc()245 return None246 # save as file if needed247 if filename:248 aircv.imwrite(filename, screen, quality, max_size=max_size)249 return screen250 else:251 raise Exception('Unsupport this keyword')252 def text(self, text, enter=True, locator=None, **kwargs):253 if locator is not None:254 if enter:255 text += '\n'256 element = self._element_find(locator, True, True)257 ActionChains(self.driver).send_keys_to_element(element, text).perform()258 else:259 raise Exception('Unsupport this keyword')260 def air_keyevent(self, keyname, **kwargs):261 if self._is_ios():262 return self.driver.press_button(keyname)263 elif self._is_android():264 self.shell("input keyevent {}".format(keyname.upper()))265 else:266 raise Exception('Unsupport this keyword')267 def double_click(self, pos):268 if self._is_ios() or self._is_android():269 self.touch(pos)270 time.sleep(0.05)271 self.touch(pos)272 else:273 raise Exception('Unsupport this keyword')274 def touch(self, pos, duration=0, **kwargs):275 if not isinstance(pos, (list, tuple)):276 raise Exception('params pos is must be tuple or list, but pos is {}'.format(type(pos)))277 if self._is_ios() or self._is_android():278 self.click_a_point(x=pos[0], y=pos[1], duration=duration*1000)279 else:280 raise Exception('Unsupport this keyword')281 def wake(self):282 if self._is_ios() or self._is_android():283 self.home()284 else:285 raise Exception('Unsupport this keyword')286 def uninstall_app(self, package):287 if self._is_ios() or self._is_android():288 self.driver.remove_app(package)289 else:290 raise Exception('Unsupport this keyword')291 def clear_app(self, package):292 if self._is_ios() or self._is_android():293 self.stop_app(package)294 self.start_app(package)295 else:296 raise Exception('Unsupport this keyword')297 def stop_app(self, package):298 if self._is_ios() or self._is_android():299 self.driver.terminate_app(package)300 else:301 raise Exception('Unsupport this keyword')302 def start_app(self, package, activity=None):303 if self._is_ios() or self._is_android():304 self.driver.activate_app(package)305 else:306 raise Exception('Unsupport this keyword')307 def shell(self, cmd):308 if self._is_android():309 self.execute_adb_shell(cmd)310 else:311 raise Exception('Unsupport this keyword')312 def air_pinch(self, center=None, percent=0.5, duration=0.05, steps=1, in_or_out='in', element=None, **kwargs):313 x, y = cx, cy = (0, 0)314 if element:315 element_location = element.location316 x, y = element_location.get('x'), element_location.get('y')317 if isinstance(center, (list, tuple)): cx, cy = center 318 width, height = self.get_current_resolution()319 if x == y == cx == cy == 0: x, y = width/2, height/2320 elif cx and cy: x, y = cx, cy321 p1x, p1y = width*0.2, y322 p2x, p2y = width*0.8, y323 p1 = TouchAction(self.driver)324 p2 = TouchAction(self.driver)325 if in_or_out == 'out':326 p1.press(x=x, y=y).wait(500).move_to(x=p1x, y=p1y).wait(duration*1000).release()327 p2.press(x=x, y=y).wait(500).move_to(x=p2x, y=p2y).wait(duration*1000).release()328 else:329 p1.press(x=p1x, y=p1y).wait(500).move_to(x=x, y=y).wait(duration*1000).release()330 p2.press(x=p2x, y=p2y).wait(500).move_to(x=x, y=y).wait(duration*1000).release()331 for _ in range(steps):332 ma = MultiAction(self.driver)333 ma.add(p1, p2)334 ma.perform()335 def air_zoom(self, element, percent="200%", steps=1):336 element_location = element.location337 x, y = element_location.get('x'), element_location.get('y')338 width, height = self.get_current_resolution()339 if x == y == 0: x, y = width/2, height/2340 p1x, p1y = width*0.2, y341 p2x, p2y = width*0.8, y342 p1 = TouchAction(self.driver)343 p2 = TouchAction(self.driver)344 p1.press(x=x, y=y).wait(500).move_to(x=p1x, y=p1y).wait(50).release()345 p2.press(x=x, y=y).wait(500).move_to(x=p2x, y=p2y).wait(50).release()346 for _ in range(steps):347 ma = MultiAction(self.driver)348 ma.add(p1, p2)349 ma.perform()350 def air_swipe(self, start_x=None, start_y=None, offset_x=None, offset_y=None, duration=0.1, **kwargs):351 if self._is_ios() or self._is_android():352 if isinstance(start_x, (list, tuple)):353 duration = float(duration) * 1000354 offset_x = start_y and start_y[0]355 offset_y = start_y and start_y[1]356 start_y = start_x[1]357 start_x = start_x[0]358 self.driver.air_swipe(start_x=start_x, start_y=start_y, end_x=offset_x, end_y=offset_y, duration=duration, **kwargs)359 else:360 raise Exception('Unsupport this keyword')361 def get_current_resolution(self):362 size = self.driver.get_window_size()...

Full Screen

Full Screen

context.py

Source:context.py Github

copy

Full Screen

1from django.utils.deprecation import MiddlewareMixin2from apps.core import utils3logger = utils.get_logger(__name__)4class AppContext(object):5 """6 A singleton object to scrape META data from HTTP Request Header7 usage:8 ip_address = AppContext.instance().ip_address9 app_version = AppContext.instance().app_version10 """11 __instance = None12 def __init__(self):13 if AppContext.__instance is not None:14 return15 self._user = None16 self._ip_address = None17 self._app_version = None18 self._is_ios = False19 self._is_android = False20 self._platform = None21 self._device_id = None22 self._timezone = None23 self._platform_version = None24 AppContext.__instance = self25 @staticmethod26 def instance():27 if AppContext.__instance is None:28 AppContext()29 return AppContext.__instance30 @property31 def user(self):32 return self._user33 @user.setter34 def user(self, value):35 self._user = value36 @property37 def app_version(self):38 return self._app_version39 @app_version.setter40 def app_version(self, value):41 self._app_version = value42 @property43 def ip_address(self):44 return self._ip_address45 @ip_address.setter46 def ip_address(self, value):47 self._ip_address = value48 @property49 def is_ios(self):50 return self._is_ios51 @is_ios.setter52 def is_ios(self, value):53 self._is_ios = value54 @property55 def is_android(self):56 return self._is_android57 @is_android.setter58 def is_android(self, value):59 self._is_android = value60 @property61 def device_id(self):62 return self._device_id63 @device_id.setter64 def device_id(self, value):65 self._device_id = value66 @property67 def platform_version(self):68 return self._platform_version69 @platform_version.setter70 def platform_version(self, value):71 self._platform_version = value72 @property73 def platform(self):74 return self._platform75 @platform.setter76 def platform(self, value):77 self._platform = value78class AppContextMiddleware(MiddlewareMixin):79 def process_request(self, request):80 try:81 context = AppContext.instance()82 context.user = request.user83 context.app_version = utils.get_app_version(request=request)84 context.device_id = utils.get_device_id(request=request)85 context.platform = utils.get_platform(request=request)86 context.platform_version = utils.get_platform_version(request=request)87 except Exception as e:88 logger.info("===== Exception in set context ======")...

Full Screen

Full Screen

scanner.py

Source:scanner.py Github

copy

Full Screen

1from flask import request2import urllib3def get_scanner_launch_uri(return_url):4 if _is_ios():5 return 'mochabarcode://' + 'CALLBACK=' + return_url6 else:7 return 'zxing://scan/?' + 'ret=' + urllib.parse.quote_plus(return_url) + '&SCAN_FORMATS=QR_CODE,CODE_39,CODE_128,CODABAR'8def _is_ios():...

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 robotframework-appiumlibrary 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