Skip to content

Commit

Permalink
feat: update visual testing report to avoid visualization problems in…
Browse files Browse the repository at this point in the history
… jenkins
  • Loading branch information
rgonalo committed Mar 2, 2022
1 parent 5e67d8d commit 1dcefde
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ v2.4.0

- Add set_file_path and set_base64_path functions to dataset module, to set base paths for FILE and BASE64 mappings
- Fix detection of POEditor configuration not available
- Visual testing baseline images are copied to output folder to facilitate report visualization in Jenkins
- Visual testing folder is duplicated to *latest* folder to allow HTML Publisher Jenkins plugin to access to it

v2.3.0
------
Expand Down
13 changes: 13 additions & 0 deletions docs/visual_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,16 @@ Toolium properties related to Visual Testing are stored in properties.cfg as ::
- *pil*: uses Pillow to compare images. It's the default option and it's installed as a Toolium dependency.
- *perceptualdiff*: uses `PerceptualDiff <http://pdiff.sourceforge.net>`_ to compare images. It is a faster library and besides generates a diff image, highlighting the differences between the baseline image and the new screenshot. It requires to be installed separately and depends on your host.
- *imagemagick*: uses `ImageMagick <http://www.imagemagick.org>`_ to compare images. It also generates a diff image, highlighting the differences in a more visual way than perceptualdiff. It requires to be installed separately and depends on your host.

How to view report in Jenkins?
------------------------------

Add action
Select Publish HTML Reports
Configure `output/visualtests/latest` folder to be archive
Configure `VisualTests.html` as index page

.. image:: visual_testing_jenkins.jpg
:scale: 50%

Chrome problems: https://stackoverflow.com/questions/69928196/chrome-not-sending-session-cookie-for-css-files-published-on-jenkins
Binary file added docs/visual_testing_jenkins.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions toolium/driver_wrappers_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def close_drivers(cls, scope, test_name, test_passed=True, context=None):
context.dyn_env.execute_after_scenario_steps(context)
# Save webdriver logs on error or if it is enabled
cls.save_all_webdriver_logs(test_name, test_passed)
elif scope == 'session':
from toolium.visual_test import VisualTest
VisualTest.update_latest_report()

# Close browser and stop driver if it must not be reused
reuse_driver = cls.get_default_wrapper().should_reuse_driver(scope, test_passed, context)
Expand Down
13 changes: 10 additions & 3 deletions toolium/test/test_driver_wrappers_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from toolium.config_files import ConfigFiles
from toolium.driver_wrapper import DriverWrapper
from toolium.driver_wrappers_pool import DriverWrappersPool
from toolium.visual_test import VisualTest


@pytest.fixture
Expand Down Expand Up @@ -102,16 +103,22 @@ def test_connect_default_driver_wrapper_already_connected(driver_wrapper):
@pytest.mark.parametrize("scope", close_drivers_scopes)
def test_close_drivers_function(scope, driver_wrapper):
DriverWrappersPool.save_all_webdriver_logs = mock.MagicMock()
VisualTest.update_latest_report = mock.MagicMock()

# Close drivers
DriverWrappersPool.close_drivers(scope, 'test_name')

# Check that save_all_webdriver_logs method has been called only in function scope
# Check that update_latest_report method has been called only in session scope
if scope == 'function':
# Check that save_all_webdriver_logs has been called
DriverWrappersPool.save_all_webdriver_logs.assert_called_once_with('test_name', True)
else:
# Check that save_all_webdriver_logs has not been called
VisualTest.update_latest_report.assert_not_called()
elif scope == 'module':
DriverWrappersPool.save_all_webdriver_logs.assert_not_called()
VisualTest.update_latest_report.assert_not_called()
elif scope == 'session':
DriverWrappersPool.save_all_webdriver_logs.assert_not_called()
VisualTest.update_latest_report.assert_called_once_with()


def test_find_parent_directory_relative():
Expand Down
20 changes: 18 additions & 2 deletions toolium/visual_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import shutil
from io import BytesIO
from os import path

from selenium.common.exceptions import NoSuchElementException

from toolium.driver_wrappers_pool import DriverWrappersPool
Expand Down Expand Up @@ -321,7 +320,11 @@ def _add_result_to_report(self, result, report_name, image_file, baseline_file,
:param message: error message
"""
self.results[result] += 1
row = self._get_html_row(result, report_name, image_file, baseline_file, message)
output_baseline_file = None
if baseline_file is not None:
output_baseline_file = os.path.join(self.output_directory, os.path.basename(baseline_file))
shutil.copyfile(baseline_file, output_baseline_file)
row = self._get_html_row(result, report_name, image_file, output_baseline_file, message)
self._add_data_to_report_before_tag(row, '</tbody>')
self._update_report_summary()

Expand Down Expand Up @@ -427,3 +430,16 @@ def _get_diff_message(message, image_size):
diff_message = message

return diff_message

@staticmethod
def update_latest_report():
"""
Duplicate current visual testing report into latest folder
"""
if os.path.exists(DriverWrappersPool.visual_output_directory):
latest_directory = os.path.join(os.path.dirname(DriverWrappersPool.visual_output_directory), 'latest')
if os.path.exists(latest_directory):
shutil.rmtree(latest_directory)
print('TMP latest removed')
print(f'TMP copying {DriverWrappersPool.visual_output_directory}')
shutil.copytree(DriverWrappersPool.visual_output_directory, latest_directory)

0 comments on commit 1dcefde

Please sign in to comment.