From 8abc76b84001f68428792e27219221b3522c8fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Gonz=C3=A1lez=20Alonso?= Date: Fri, 17 Sep 2021 15:26:59 +0200 Subject: [PATCH] fix: allow custom parent in group element #239 (#240) --- CHANGELOG.rst | 2 ++ toolium/pageelements/group_page_element.py | 4 ++-- toolium/pageelements/page_element.py | 2 +- toolium/test/pageelements/test_page_element.py | 6 +++--- toolium/test/pageelements/test_page_elements.py | 2 +- .../test/pageelements/test_page_elements_groups.py | 14 +++++++------- .../test/pageelements/test_page_nested_groups.py | 8 ++++---- toolium/test/pageobjects/test_page_object.py | 6 +++--- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 11cfbe05..8f0bc80c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,8 @@ v2.1.1 *Release date: In development* +- Avoid to overwrite parent in group elements when a custom parent is defined + v2.1.0 ------ diff --git a/toolium/pageelements/group_page_element.py b/toolium/pageelements/group_page_element.py index 4603bd11..e251be4c 100644 --- a/toolium/pageelements/group_page_element.py +++ b/toolium/pageelements/group_page_element.py @@ -70,6 +70,6 @@ def reset_object(self, driver_wrapper=None): self._web_element = None for element in self._get_page_elements(): element.reset_object(driver_wrapper) - if isinstance(element, (PageElement, PageElements)): - # If element is not a page object, update element parent + if isinstance(element, (PageElement, PageElements)) and element.parent is None: + # If element is not a page object and it has not a custom parent, update element parent element.parent = self diff --git a/toolium/pageelements/page_element.py b/toolium/pageelements/page_element.py index 9eea47c4..5a047d9f 100644 --- a/toolium/pageelements/page_element.py +++ b/toolium/pageelements/page_element.py @@ -113,7 +113,7 @@ def _find_web_element(self): 'querySelector("%s")' % (self.shadowroot, self.locator[1])) else: - # Element will be finded from parent element or from driver + # Element will be searched from parent element or from driver base = self.utils.get_web_element(self.parent) if self.parent else self.driver # Find elements and get the correct index or find a single element self._web_element = base.find_elements(*self.locator)[self.order] if self.order \ diff --git a/toolium/test/pageelements/test_page_element.py b/toolium/test/pageelements/test_page_element.py index a68da56f..1e05269c 100644 --- a/toolium/test/pageelements/test_page_element.py +++ b/toolium/test/pageelements/test_page_element.py @@ -40,13 +40,13 @@ class MenuGroup(Group): class RegisterPageObject(PageObject): username = PageElement(By.XPATH, '//input[0]') - password = PageElement(By.ID, 'password', username) + password = PageElement(By.ID, 'password', parent=username) menu_group = MenuGroup(By.ID, 'menu') def init_page_elements(self): self.language = PageElement(By.ID, 'language') - self.email = PageElement(By.ID, 'email', mock_element) - self.address = PageElement(By.ID, 'address', (By.ID, 'parent')) + self.email = PageElement(By.ID, 'email', parent=mock_element) + self.address = PageElement(By.ID, 'address', parent=(By.ID, 'parent')) self.address_shadowroot = PageElement(By.CSS_SELECTOR, '#address', shadowroot='shadowroot_css') self.address_shadowroot_by_id = PageElement(By.ID, 'address', shadowroot='shadowroot_css') self.element_webview = PageElement(By.ID, 'webview', webview=True) diff --git a/toolium/test/pageelements/test_page_elements.py b/toolium/test/pageelements/test_page_elements.py index 77e0bd94..e9e577d9 100644 --- a/toolium/test/pageelements/test_page_elements.py +++ b/toolium/test/pageelements/test_page_elements.py @@ -34,7 +34,7 @@ class LoginPageObject(PageObject): 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', (By.ID, 'parent')) + self.inputs_with_parent = PageElements(By.XPATH, '//input', parent=(By.ID, 'parent')) @pytest.fixture diff --git a/toolium/test/pageelements/test_page_elements_groups.py b/toolium/test/pageelements/test_page_elements_groups.py index bcea69ca..ae1dc581 100644 --- a/toolium/test/pageelements/test_page_elements_groups.py +++ b/toolium/test/pageelements/test_page_elements_groups.py @@ -31,7 +31,7 @@ class Column(Group): def init_page_elements(self): self.input = InputText(By.XPATH, './/input') self.link = Link(By.XPATH, './/a') - self.input_with_parent = InputText(By.XPATH, './/input', (By.XPATH, './/parent')) + self.input_with_parent = InputText(By.XPATH, './/input', parent=self.link) class Columns(PageElements): @@ -108,15 +108,15 @@ def test_reset_object_page_elements_groups(driver_wrapper): assert column_21.input._web_element is not None assert column_21.link._web_element is not None assert column_21.input_with_parent._web_element is not None - # Check that the group elements have the group as parent + # Check that the group elements have the group as parent, except input_with_parent that has its custom parent assert column_11.parent == row_1 assert column_21.parent == row_2 assert column_11.input.parent == column_11 assert column_11.link.parent == column_11 - assert column_11.input_with_parent.parent == column_11 + assert column_11.input_with_parent.parent == column_11.link assert column_21.input.parent == column_21 assert column_21.link.parent == column_21 - assert column_21.input_with_parent.parent == column_21 + assert column_21.input_with_parent.parent == column_21.link table_page.reset_object() @@ -137,12 +137,12 @@ def test_reset_object_page_elements_groups(driver_wrapper): assert column_21.input._web_element is None assert column_21.link._web_element is None assert column_21.input_with_parent._web_element is None - # Check that the group elements have the group as parent + # Check that the group elements have the group as parent, except input_with_parent that has its custom parent assert column_11.parent == row_1 assert column_21.parent == row_2 assert column_11.input.parent == column_11 assert column_11.link.parent == column_11 - assert column_11.input_with_parent.parent == column_11 + assert column_11.input_with_parent.parent == column_11.link assert column_21.input.parent == column_21 assert column_21.link.parent == column_21 - assert column_21.input_with_parent.parent == column_21 + assert column_21.input_with_parent.parent == column_21.link diff --git a/toolium/test/pageelements/test_page_nested_groups.py b/toolium/test/pageelements/test_page_nested_groups.py index 95e9eb8c..4678609d 100644 --- a/toolium/test/pageelements/test_page_nested_groups.py +++ b/toolium/test/pageelements/test_page_nested_groups.py @@ -30,7 +30,7 @@ class InnerGroup(Group): def init_page_elements(self): self.input = InputText(By.XPATH, './/input') - self.input_with_parent = InputText(By.XPATH, './/input', (By.XPATH, './/parent')) + self.input_with_parent = InputText(By.XPATH, './/input', parent=self.input) class OuterGroup(Group): @@ -73,7 +73,7 @@ def test_reset_object_nested_groups(driver_wrapper): assert nested_page.outer.inner.input_with_parent._web_element is None assert nested_page.outer.inner.parent == nested_page.outer assert nested_page.outer.inner.input.parent == nested_page.outer.inner - assert nested_page.outer.inner.input_with_parent.parent == nested_page.outer.inner + assert nested_page.outer.inner.input_with_parent.parent == nested_page.outer.inner.input nested_page.outer.inner.input.web_element nested_page.outer.inner.input_with_parent.web_element @@ -85,7 +85,7 @@ def test_reset_object_nested_groups(driver_wrapper): assert nested_page.outer.inner.input_with_parent._web_element is not None assert nested_page.outer.inner.parent == nested_page.outer assert nested_page.outer.inner.input.parent == nested_page.outer.inner - assert nested_page.outer.inner.input_with_parent.parent == nested_page.outer.inner + assert nested_page.outer.inner.input_with_parent.parent == nested_page.outer.inner.input nested_page.outer.reset_object() @@ -96,4 +96,4 @@ def test_reset_object_nested_groups(driver_wrapper): assert nested_page.outer.inner.input_with_parent._web_element is None assert nested_page.outer.inner.parent == nested_page.outer assert nested_page.outer.inner.input.parent == nested_page.outer.inner - assert nested_page.outer.inner.input_with_parent.parent == nested_page.outer.inner + assert nested_page.outer.inner.input_with_parent.parent == nested_page.outer.inner.input diff --git a/toolium/test/pageobjects/test_page_object.py b/toolium/test/pageobjects/test_page_object.py index 5c25b813..bdce1a8e 100644 --- a/toolium/test/pageobjects/test_page_object.py +++ b/toolium/test/pageobjects/test_page_object.py @@ -46,12 +46,12 @@ def init_page_elements(self): class RegisterPageObject(PageObject): username = PageElement(By.XPATH, '//input[0]', wait=True) - password = PageElement(By.ID, 'password', username) + password = PageElement(By.ID, 'password', parent=username) def init_page_elements(self): self.language = PageElement(By.ID, 'language') - self.email = PageElement(By.ID, 'email', mock_element) - self.address = PageElement(By.ID, 'address', (By.ID, 'parent')) + self.email = PageElement(By.ID, 'email', parent=mock_element) + self.address = PageElement(By.ID, 'address', parent=(By.ID, 'parent')) self.inputs = PageElements(By.XPATH, '//input') self.menu = MenuPageObject(wait=True) self.menu_group = MenuGroup(By.ID, 'menu', wait=True)