Skip to content

Commit

Permalink
fix: show parent locator in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Apr 20, 2022
1 parent 7fe7f05 commit 9b81d32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,7 @@ v2.5.1

- Update map_param method to allow recursive replacements
- Update replace_param function to allow multiple date expressions in the same param
- Fix error message to show parent locator instead of object reference when an element is not found

v2.5.0
------
Expand Down
17 changes: 15 additions & 2 deletions toolium/pageelements/page_element.py
Expand Up @@ -86,7 +86,7 @@ def web_element(self):
try:
self._find_web_element()
except NoSuchElementException as exception:
parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else ''
parent_msg = f" and parent locator {self.parent_locator_str()}" if self.parent else ''
msg = "Page element of type '%s' with locator %s%s not found"
self.logger.error(msg, type(self).__name__, self.locator, parent_msg)
exception.msg += "\n {}".format(msg % (type(self).__name__, self.locator, parent_msg))
Expand Down Expand Up @@ -169,6 +169,19 @@ def _ios_automatic_context_selection(self):
if self.driver.context != PageElement.native_context:
self.driver.switch_to.context(PageElement.native_context)

def parent_locator_str(self):
"""Return string with locator tuple for parent element
:returns: parent element locator
"""
if isinstance(self.parent, PageElement):
parent_locator = str(self.parent.locator)
elif isinstance(self.parent, tuple):
parent_locator = str(self.parent)
else:
parent_locator = '[WebElement without locator]'
return parent_locator

def scroll_element_into_view(self):
"""Scroll element into view
Expand Down Expand Up @@ -218,7 +231,7 @@ def _wait_until_condition(self, condition, timeout=None):
condition_msg = 'not found or is not clickable'
self.utils.wait_until_element_clickable(self, timeout)
except TimeoutException as exception:
parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else ''
parent_msg = f" and parent locator {self.parent_locator_str()}" if self.parent else ''
timeout = timeout if timeout else self.utils.get_explicitly_wait()
msg = "Page element of type '%s' with locator %s%s %s after %s seconds"
msg = msg % (type(self).__name__, self.locator, parent_msg, condition_msg, timeout)
Expand Down

0 comments on commit 9b81d32

Please sign in to comment.