Skip to main content

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:

Release files for pytest-vtestify 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-vtestify 0.2.1
File Size Uploaded
pytest_vtestify-0.2.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-vtestify 0.2.1
File Interpreter ABI Platform
pytest_vtestify-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / pytest_vtestify-0.2.1.tar.gz

Download URL pytest_vtestify-0.2.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4c99c6c8a00e9ae040b9f2dc4cb628b8985bca52d97836ac2a8ce8878dcb3653
BLAKE2b-256 checksum
How to use checksums
4dc03c236e07fa0976e6f9331084fc27f10ea1e74b5df15f4a267a721e035b7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / pytest_vtestify-0.2.1-py3-none-any.whl

Download URL pytest_vtestify-0.2.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
029adccd21fc05c830f43dc369f918c8ec97fe255b15236fce914803d1aedd95
BLAKE2b-256 checksum
How to use checksums
52502321712ae6273e2cfab87f6cb22207ebe35efc665f44b2b4b43d676338ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page