Skip to content

Commit

Permalink
fix: allow custom parent in group element #239 (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo authored Sep 17, 2021
1 parent 42c4d20 commit 8abc76b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------

Expand Down
4 changes: 2 additions & 2 deletions toolium/pageelements/group_page_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion toolium/pageelements/page_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions toolium/test/pageelements/test_page_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion toolium/test/pageelements/test_page_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions toolium/test/pageelements/test_page_elements_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand All @@ -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
8 changes: 4 additions & 4 deletions toolium/test/pageelements/test_page_nested_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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
6 changes: 3 additions & 3 deletions toolium/test/pageobjects/test_page_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8abc76b

Please sign in to comment.