Skip to content

Commit

Permalink
Merge 3a6c866 into 9a73d65
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed Apr 24, 2020
2 parents 9a73d65 + 3a6c866 commit eb9b6ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -10,6 +10,7 @@ v1.6.2.dev0
- Add `ssl` config property in [Server] section to allow using https in Selenium Grid url
- Visual testing comparison must fail when baseline does not exist and save mode is disabled
- Fix dynamic environment behaviour, after scenario/feature actions are executed when before scenario/feature actions fail
- Fix unit tests to work without any additional dependencies

v1.6.1
------
Expand Down
31 changes: 23 additions & 8 deletions toolium/test/test_visual_test.py
Expand Up @@ -243,7 +243,22 @@ def assert_image(visual, img, img_name, expected_image_filename):

# Output image and expected image must be equal
expected_image = os.path.join(root_path, 'resources', expected_image_filename + '.png')
MagickEngine().assertSameFiles(result_file, expected_image, 0.1)
compare_image_files(result_file, expected_image)


def compare_image_files(image, expected_image, threshold=0.1):
"""Compare two images
:param image: file path image to compare
:param expected_image: expected image
:param threshold: allowed threshold
"""
# Pil needs a pixel number threshold instead of a percentage threshold
img = Image.open(expected_image)
width, height = img.size
threshold = int(width * height * threshold)

PilEngine().assertSameFiles(image, expected_image, threshold)


def test_crop_element(driver_wrapper):
Expand Down Expand Up @@ -475,7 +490,7 @@ def test_assert_screenshot_full_and_save_baseline(driver_wrapper):

# Output image and new baseline image must be equal
baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_full.png')
MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
compare_image_files(output_file, baseline_file)


def test_assert_screenshot_element_and_save_baseline(driver_wrapper):
Expand All @@ -497,11 +512,11 @@ def test_assert_screenshot_element_and_save_baseline(driver_wrapper):
# Check cropped image
expected_image = os.path.join(root_path, 'resources', 'register_cropped_element.png')
output_file = os.path.join(visual.output_directory, '01_screenshot_elem__screenshot_suffix.png')
MagickEngine().assertSameFiles(output_file, expected_image, 0.1)
compare_image_files(output_file, expected_image)

# Output image and new baseline image must be equal
baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_elem.png')
MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
compare_image_files(output_file, baseline_file)


def test_assert_screenshot_full_and_compare(driver_wrapper):
Expand Down Expand Up @@ -603,11 +618,11 @@ def test_assert_screenshot_mobile_resize_and_exclude(driver_wrapper):
# Check cropped image
expected_image = os.path.join(root_path, 'resources', 'ios_excluded.png')
output_file = os.path.join(visual.output_directory, '01_screenshot_ios__screenshot_suffix.png')
MagickEngine().assertSameFiles(output_file, expected_image, 0.1)
compare_image_files(output_file, expected_image)

# Output image and new baseline image must be equal
baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_ios.png')
MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
compare_image_files(output_file, baseline_file)


def test_assert_screenshot_mobile_web_resize_and_exclude(driver_wrapper):
Expand Down Expand Up @@ -637,11 +652,11 @@ def test_assert_screenshot_mobile_web_resize_and_exclude(driver_wrapper):
# Check cropped image
expected_image = os.path.join(root_path, 'resources', 'ios_web_exclude.png')
output_file = os.path.join(visual.output_directory, '01_screenshot_ios_web__screenshot_suffix.png')
MagickEngine().assertSameFiles(output_file, expected_image, 0.1)
compare_image_files(output_file, expected_image)

# Output image and new baseline image must be equal
baseline_file = os.path.join(root_path, 'output', 'visualtests', 'baseline', 'firefox', 'screenshot_ios_web.png')
MagickEngine().assertSameFiles(output_file, baseline_file, 0.1)
compare_image_files(output_file, baseline_file)


def test_assert_screenshot_str_threshold(driver_wrapper):
Expand Down

0 comments on commit eb9b6ac

Please sign in to comment.