How to use _ios_automatic_context_selection method in toolium

Best Python code snippet using toolium_python

page_element.py

Source:page_element.py Github

copy

Full Screen

...84 if self.driver_wrapper.config.getboolean_optional('Driver', 'automatic_context_selection'):85 if self.driver_wrapper.is_android_test():86 self._android_automatic_context_selection()87 elif self.driver_wrapper.is_ios_test():88 self._ios_automatic_context_selection()89 # If the element is encapsulated we use the shadowroot tag in yaml (eg. Shadowroot: root_element_name)90 if self.shadowroot:91 if self.locator[0] != By.CSS_SELECTOR:92 raise Exception('Locator type should be CSS_SELECTOR using shadowroot but found: '93 '%s' % self.locator[0])94 # querySelector only support CSS SELECTOR locator95 self._web_element = self.driver.execute_script('return document.querySelector("%s").shadowRoot.'96 'querySelector("%s")' % (self.shadowroot,97 self.locator[1]))98 else:99 # Element will be searched from parent element or from driver100 base = self.utils.get_web_element(self.parent) if self.parent else self.driver101 # Find elements and get the correct index or find a single element102 self._web_element = base.find_elements(*self.locator)[self.order] if self.order \103 else base.find_element(*self.locator)104 def _android_automatic_context_selection(self):105 """Change context selection depending if the element is a webview for android devices"""106 # we choose the appPackage webview context, and select the first window returned by mobile: getContexts107 if self.webview:108 context = None109 window_handle = None110 if self.webview_context_selection_callback:111 context, window_handle = self.webview_context_selection_callback(*self.webview_csc_args)112 else:113 app_web_context = "{}_{}".format(PageElement.webview_context_prefix,114 self.driver.capabilities['appPackage'])115 contexts = self.driver.execute_script('mobile: getContexts')116 context_dict = next(117 (item for item in contexts if 'webviewName' in item and item['webviewName'] == app_web_context),118 None)119 if context_dict:120 context = app_web_context121 window_handle = 'CDwindow-{}'.format(context_dict['pages'][0]['id'])122 if context:123 if self.driver.context != context:124 self.driver.switch_to.context(context)125 if self.driver.current_window_handle != window_handle:126 self.driver.switch_to.window(window_handle)127 else:128 raise KeyError("WEBVIEW context not found")129 else:130 if self.driver.context != PageElement.native_context:131 self.driver.switch_to.context(PageElement.native_context)132 def _ios_automatic_context_selection(self):133 """Change context selection depending if the element is a webview for ios devices"""134 # we choose the last webview context returned by mobile: getContexts for the bundleid135 if self.webview:136 if self.webview_context_selection_callback:137 context_id = self.webview_context_selection_callback(*self.webview_csc_args)138 else:139 contexts = self.driver.execute_script('mobile: getContexts')140 context_id = next(141 (item['id'] for item in reversed(contexts) if142 'bundleId' in item and item['bundleId'] == self.driver.capabilities['bundleId']),143 None)144 if context_id:145 if self.driver.context != context_id:146 self.driver.switch_to.context(context_id)...

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