How to use get_safari_navigation_bar_height method in toolium

Best Python code snippet using toolium_python

utilities.py

Source:utilities.py Github

copy

Full Screen

...329 web_element = self.get_web_element(element)330 location = web_element.location331 size = web_element.size332 return {'x': location['x'] + (size['width'] / 2), 'y': location['y'] + (size['height'] / 2)}333 def get_safari_navigation_bar_height(self):334 status_bar_height = 0335 if self.driver_wrapper.is_ios_test() and self.driver_wrapper.is_web_test():336 # ios 7.1, 8.3337 status_bar_height = 64338 return status_bar_height339 def get_window_size(self):340 if not self._window_size:341 if self.driver_wrapper.is_android_web_test() and self.driver_wrapper.driver.current_context != 'NATIVE_APP':342 window_width = self.driver_wrapper.driver.execute_script("return window.innerWidth")343 window_height = self.driver_wrapper.driver.execute_script("return window.innerHeight")344 self._window_size = {'width': window_width, 'height': window_height}345 else:346 self._window_size = self.driver_wrapper.driver.get_window_size()347 return self._window_size348 def get_native_coords(self, coords):349 web_window_size = self.get_window_size()350 self.driver_wrapper.driver.switch_to.context('NATIVE_APP')351 native_window_size = self.driver_wrapper.driver.get_window_size()352 scale = native_window_size['width'] / web_window_size['width']353 offset_y = self.get_safari_navigation_bar_height()354 native_coords = {'x': coords['x'] * scale, 'y': coords['y'] * scale + offset_y}355 self.logger.debug('Converted web coords %s into native coords %s', coords, native_coords)356 return native_coords357 def swipe(self, element, x, y, duration=None):358 if not self.driver_wrapper.is_mobile_test():359 raise Exception('Swipe method is not implemented in Selenium')360 # Get center coordinates of element361 center = self.get_center(element)362 initial_context = self.driver_wrapper.driver.current_context363 if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':364 center = self.get_native_coords(center)365 # Android needs absolute end coordinates and ios needs movement366 end_x = x if self.driver_wrapper.is_ios_test() else center['x'] + x367 end_y = y if self.driver_wrapper.is_ios_test() else center['y'] + y...

Full Screen

Full Screen

driver_utils.py

Source:driver_utils.py Github

copy

Full Screen

...243 web_element = self.get_web_element(element)244 location = web_element.location245 size = web_element.size246 return {'x': location['x'] + (size['width'] / 2), 'y': location['y'] + (size['height'] / 2)}247 def get_safari_navigation_bar_height(self):248 """Get the height of Safari navigation bar249 :returns: height of navigation bar250 """251 status_bar_height = 0252 if self.driver_wrapper.is_ios_test() and self.driver_wrapper.is_web_test():253 # ios 7.1, 8.3254 status_bar_height = 64255 return status_bar_height256 def get_window_size(self):257 """Generic method to get window size using a javascript workaround for mobile web tests258 :returns: dict with window width and height259 """260 if not self._window_size:261 is_mobile_web = self.driver_wrapper.is_android_web_test() or self.driver_wrapper.is_ios_web_test()262 if is_mobile_web and self.driver_wrapper.driver.current_context != 'NATIVE_APP':263 window_width = self.driver_wrapper.driver.execute_script("return window.screen.width")264 window_height = self.driver_wrapper.driver.execute_script("return window.screen.height")265 self._window_size = {'width': window_width, 'height': window_height}266 else:267 self._window_size = self.driver_wrapper.driver.get_window_size()268 return self._window_size269 def get_native_coords(self, coords):270 """Convert web coords into native coords. Assumes that the initial context is WEBVIEW and switches to271 NATIVE_APP context.272 :param coords: dict with web coords, e.g. {'x': 10, 'y': 10}273 :returns: dict with native coords274 """275 web_window_size = self.get_window_size()276 self.driver_wrapper.driver.switch_to.context('NATIVE_APP')277 native_window_size = self.driver_wrapper.driver.get_window_size()278 scale = native_window_size['width'] / web_window_size['width']279 offset_y = self.get_safari_navigation_bar_height()280 native_coords = {'x': coords['x'] * scale, 'y': coords['y'] * scale + offset_y}281 self.logger.debug('Converted web coords %s into native coords %s', coords, native_coords)282 return native_coords283 def swipe(self, element, x, y, duration=None):284 """Swipe over an element285 :param element: either a WebElement, PageElement or element locator as a tuple (locator_type, locator_value)286 :param x: horizontal movement287 :param y: vertical movement288 :param duration: time to take the swipe, in ms289 """290 if not self.driver_wrapper.is_mobile_test():291 raise Exception('Swipe method is not implemented in Selenium')292 # Get center coordinates of element293 center = self.get_center(element)...

Full Screen

Full Screen

visual_test.py

Source:visual_test.py Github

copy

Full Screen

...157 offset_x = -scroll_x158 offset_y = -scroll_y159 else:160 offset_x = 0161 offset_y = self.utils.get_safari_navigation_bar_height()162 location = web_element.location163 size = web_element.size164 return (int(location['x']) + offset_x, int(location['y'] + offset_y),165 int(location['x'] + offset_x + size['width']), int(location['y'] + offset_y + size['height']))166 def crop_element(self, img, web_element):167 if web_element:168 element_box = self.get_element_box(web_element)169 # Reduce element box if it is greater than image size170 element_max_x = img.size[0] if element_box[2] > img.size[0] else element_box[2]171 element_max_y = img.size[1] if element_box[3] > img.size[1] else element_box[3]172 element_box = (element_box[0], element_box[1], element_max_x, element_max_y)173 img = img.crop(element_box)174 return img175 def exclude_elements(self, img, web_elements):...

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 toolium 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