Skip to content

Commit

Permalink
reduce method complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Mar 21, 2024
1 parent 507287b commit 4121bcf
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions toolium/visual_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +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_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)}')
exclude_web_elements = _get_exclude_web_elements(self, 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 @@ -151,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 4121bcf

Please sign in to comment.