Skip to main content

A pytest plugin for visual assertion using SSIM and image comparison.

Project description

pytest-vtestify Downloads

pytest-vtestify

pytest-vtestify is a pytest plugin designed for visual assertion and image comparison, utilizing Structural Similarity Index (SSIM). This package is perfect for validating UI changes or detecting regressions in web and software interfaces.

Features

  • Compare two images using SSIM.
  • Visualize the differences between images.
  • Automatically generate and save the diff image with bounding boxes.
  • Integrate seamlessly into pytest framework for automated testing workflows.

Installation

To install the package, simply run:

pip install pytest-vtestify

Usage

Basic Usage

You can integrate pytest-vtestify into your test suite by using the visual_assertion fixture. Below is an example of how to compare two images and generate a diff image.

def test_visual_comparison(visual_assertion):
    image1 = "path/to/expected_image.png"
    image2 = "path/to/actual_image.png"
    visual_assertion(image1, image2, threshold=0.95)

Web Automation Testing with Selenium

pytest-vtestify can also be used to perform visual regression testing in web automation projects, especially when working with dynamic web content. Here's an example using Selenium:

  1. Capture screenshots of the expected and actual web pages.
  2. Use visual_assertion to compare them.

Example using Selenium:

from selenium import webdriver

def test_webpage_visual_comparison(visual_assertion):
    driver = webdriver.Chrome()
    
    # Navigate to the webpage and capture a screenshot
    driver.get('https://example.com')
    driver.save_screenshot('actual_page.png')
    
    # Assume 'expected_page.png' is the expected screenshot
    expected_image = 'path/to/expected_page.png'
    actual_image = 'actual_page.png'
    
    # Compare screenshots
    visual_assertion(expected_image, actual_image, threshold=0.98)
    
    driver.quit()

In this example:

Selenium's webdriver.Chrome() is used to open a web page. The actual web page screenshot is compared to an expected screenshot using pytest-vtestify. The threshold value specifies how similar the images should be to pass the test.

Diff Image Output

When the comparison fails, a diff image will be automatically generated and saved in report/images/diff.png. This diff image contains:

  • The expected image.
  • The actual image.
  • The diff image with bounding boxes highlighting the differences.

Folder Structure

If the report/images folder doesn't exist, the plugin will create it during the test execution and place the diff image inside it.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Instructions for Using pytest-vtestify with Selenium

In the example provided for web automation testing with Selenium:

  • Selenium takes a screenshot of a web page during a test.
  • You compare the screenshot to an "expected" image using the visual_assertion fixture from pytest-vtestify.
  • The threshold parameter determines how closely the two images should match.

This approach is commonly used in visual regression testing for web automation, helping to catch unintended UI changes or regressions.

more question find me on:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_vtestify-0.2.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_vtestify-0.2.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_vtestify-0.2.0.tar.gz.

File metadata

  • Download URL: pytest_vtestify-0.2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pytest_vtestify-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0b84fd4e80d06a565732a40f025e5233bc1f94ef2ab0745e465739ade89f66e9
MD5 73ce73321a4cd4acf23b9fbfc2f5f472
BLAKE2b-256 afd07031d7aac80d422e4cc460dc3da7eda94aa202206cd3d277019278402242

See more details on using hashes here.

File details

Details for the file pytest_vtestify-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_vtestify-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f62f7626f4d636a80b1261468b5112809f9c9312d62c26460ed34beee6db93a
MD5 7cdeba7de64af93db6b50481b2e8a052
BLAKE2b-256 09f546f1e1bd57e833ad34e6c04898a04359d1bacf7d09df48e4a37b3d6040dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page