How to use _android_automatic_context_selection method in toolium

Best Python code snippet using toolium_python

page_element.py

Source:page_element.py Github

copy

Full Screen

...82 if not self._web_element or not self.driver_wrapper.config.getboolean_optional('Driver', 'save_web_element'):83 # check context for mobile webviews84 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)...

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