diff --git a/toolium/visual_test.py b/toolium/visual_test.py index 3859c366..1f3d3015 100644 --- a/toolium/visual_test.py +++ b/toolium/visual_test.py @@ -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 @@ -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