diff --git a/toolium/pageobjects/common_object.py b/toolium/pageobjects/common_object.py index 02e77f5c..508c1a48 100644 --- a/toolium/pageobjects/common_object.py +++ b/toolium/pageobjects/common_object.py @@ -68,11 +68,13 @@ def utils(self): def _android_automatic_context_selection(self): """Change context selection depending if the element is a webview for android devices""" # we choose the appPackage webview context, and select the first window returned by mobile: getContexts - if self.webview: + if self.webview or (self.parent and self.parent.webview): context = None window_handle = None if self.webview_context_selection_callback: context, window_handle = self.webview_context_selection_callback(*self.webview_csc_args) + elif self.parent and self.parent.webview_context_selection_callback: + context, window_handle = self.parent.webview_context_selection_callback(*self.parent.webview_csc_args) else: app_web_context = "{}_{}".format(CommonObject.webview_context_prefix, self.driver.capabilities['appPackage']) diff --git a/toolium/test/pageelements/test_page_elements.py b/toolium/test/pageelements/test_page_elements.py index 28a6d078..2baaed21 100644 --- a/toolium/test/pageelements/test_page_elements.py +++ b/toolium/test/pageelements/test_page_elements.py @@ -35,6 +35,7 @@ def init_page_elements(self): self.inputs = PageElements(By.XPATH, '//input') self.links = PageElements(By.XPATH, '//a') self.inputs_with_parent = PageElements(By.XPATH, '//input', parent=(By.ID, 'parent')) + self.inputs_with_webview = PageElements(By.XPATH, '//input', webview=True) @pytest.fixture @@ -163,3 +164,20 @@ def test_reset_object(driver_wrapper): assert len(login_page.links._web_elements) == 1 assert login_page.links._page_elements[0]._web_element is not None assert page_element_21._web_element is not None + +def test_get_page_elements_without_webview(driver_wrapper): + driver_wrapper.driver.find_elements.return_value = child_elements + page_elements = LoginPageObject().inputs.page_elements + + # Check webview attribute is set to false by default in child elements + assert page_elements[0].webview == False + assert page_elements[1].webview == False + +def test_get_page_elements_with_webview(driver_wrapper): + driver_wrapper.driver.find_elements.return_value = child_elements + page_elements = LoginPageObject().inputs_with_webview.page_elements + + # Check webview attribute is set to true in child element when a Pagelements element + # is created with the webview attribute + assert page_elements[0].webview + assert page_elements[1].webview