Best Python code snippet using toolium_python
test_driver_utils.py
Source:test_driver_utils.py
...342 driver_wrapper.config.set('Driver', 'type', 'android')343 driver_wrapper.config.set('AppiumCapabilities', 'browserName', 'chrome')344 web_coords = {'x': 105, 'y': 185}345 native_coords = {'x': 52.5, 'y': 92.5}346 assert utils.get_native_coords(web_coords) == native_coords347def test_get_native_coords_ios_web(driver_wrapper, utils):348 # Configure driver mock349 web_window_size = {'width': 500, 'height': 667}350 native_window_size = {'width': 250, 'height': 450}351 driver_wrapper.driver.get_window_size.return_value = native_window_size352 utils.get_window_size = mock.MagicMock(return_value=web_window_size)353 driver_wrapper.config.set('Driver', 'type', 'ios')354 driver_wrapper.config.set('AppiumCapabilities', 'browserName', 'safari')355 web_coords = {'x': 105, 'y': 185}356 native_coords = {'x': 52.5, 'y': 156.5}357 assert utils.get_native_coords(web_coords) == native_coords358def test_swipe_android_native(driver_wrapper, utils):359 # Configure driver mock360 web_window_size = {'width': 500, 'height': 667}361 native_window_size = {'width': 250, 'height': 450}362 driver_wrapper.driver.get_window_size.side_effect = [web_window_size, native_window_size]363 driver_wrapper.driver.current_context = 'NATIVE_APP'364 driver_wrapper.config.set('Driver', 'type', 'android')365 driver_wrapper.config.set('AppiumCapabilities', 'app', 'C:/Demo.apk')366 # Create element mock367 element = get_mock_element(x=250, y=40, height=40, width=300)368 utils.swipe(element, 50, 100)369 driver_wrapper.driver.swipe.assert_called_once_with(400, 60, 450, 160, None)370def test_swipe_android_web(driver_wrapper, utils):371 # Configure driver mock...
utilities.py
Source:utilities.py
...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'] + y368 self.driver_wrapper.driver.swipe(center['x'], center['y'], end_x, end_y, duration)369 if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':370 self.driver_wrapper.driver.switch_to.context(initial_context)371 def get_web_element(self, element):372 from arc.page_elements import PageElement373 if isinstance(element, WebElement):374 web_element = element375 elif isinstance(element, PageElement):376 web_element = element.web_element377 elif isinstance(element, tuple):378 web_element = self.driver_wrapper.driver.find_element(*element)...
driver_utils.py
Source:driver_utils.py
...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)294 initial_context = self.driver_wrapper.driver.current_context295 if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':296 center = self.get_native_coords(center)297 # Android needs absolute end coordinates and ios needs movement298 end_x = x if self.driver_wrapper.is_ios_test() else center['x'] + x299 end_y = y if self.driver_wrapper.is_ios_test() else center['y'] + y300 self.driver_wrapper.driver.swipe(center['x'], center['y'], end_x, end_y, duration)301 if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':302 self.driver_wrapper.driver.switch_to.context(initial_context)303 def get_web_element(self, element):304 """Return the web element from a page element or its locator305 :param element: either a WebElement, PageElement or element locator as a tuple (locator_type, locator_value)306 :returns: WebElement object307 """308 from toolium.pageelements.page_element import PageElement309 if isinstance(element, WebElement):310 web_element = element...
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!!