Skip to content

Commit

Permalink
fix: ignore not found excluded elements in visual tests (#382)
Browse files Browse the repository at this point in the history
* fix: ignore not found excluded elements in visual tests

* reduce method complexity

* fix method call
  • Loading branch information
rgonalo authored Mar 22, 2024
1 parent b92cb7c commit 093f1c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ v3.1.4

- Add `ignore_empty` optional parameter to POEditor configuration to ignore empty translations
- Fix on swipe method. Duration from None to 0.
- Ignore not found excluded elements in visual tests

v3.1.3
------
Expand Down
26 changes: 20 additions & 6 deletions toolium/visual_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ def assert_screenshot(self, element, filename, file_suffix=None, threshold=0, ex

# Search elements
web_element = self.utils.get_web_element(element)
exclude_web_elements = []
for exclude_element in exclude_elements:
try:
exclude_web_elements.append(self.utils.get_web_element(exclude_element))
except NoSuchElementException as e:
self.logger.warning("Element to be excluded not found: %s", str(e))
exclude_web_elements = self._get_exclude_web_elements(exclude_elements)

baseline_path = os.path.join(self.baseline_directory, '{}.png'.format(filename))
filename_with_suffix = '{0}__{1}'.format(filename, file_suffix) if file_suffix else filename
Expand Down Expand Up @@ -147,6 +142,25 @@ def assert_screenshot(self, element, filename, file_suffix=None, threshold=0, ex
# Compare the screenshots
self.compare_files(report_name, output_path, baseline_path, threshold)

def _get_exclude_web_elements(self, exclude_elements):
"""Get WebElements from exclude_elements list ignoring not found elements
:param exclude_elements: list of WebElements, PageElements or element locators as a tuple (locator_type,
locator_value) that must be searched
:returns: list of WebElements to be excluded
"""
exclude_web_elements = []
for exclude_element in exclude_elements:
try:
exclude_web_element = self.utils.get_web_element(exclude_element)
if exclude_web_element:
exclude_web_elements.append(exclude_web_element)
else:
self.logger.warning('Element to be excluded not found')
except NoSuchElementException as e:
self.logger.warning(f'Element to be excluded not found: {str(e)}')
return exclude_web_elements

def get_scrolls_size(self):
"""Return Chrome and Explorer scrolls sizes if they are visible
Firefox screenshots don't contain scrolls
Expand Down

0 comments on commit 093f1c5

Please sign in to comment.