A robust visual regression testing library for Python.
Project description
Visual Guard
Visual Guard is a powerful Python library designed specifically for Visual Regression Testing. It allows you to automatically detect UI changes by comparing screenshots against approved baselines, ensuring your application looks perfect on every release.
Key Features
- Multiple Comparison Methods:
- Pixel: Strict pixel-perfect matching.
- SSIM (Structural Similarity): Human-eye perception matching (requires
scikit-image). - pHash (Perceptual Hash): Robust matching that ignores minor color shifts or scaling.
- Advanced Region Masking: Easily exclude dynamic content (like timestamps, ads, or carousels) using Rectangles or Polygons.
- Visual Reporting: Generates professional HTML reports with side-by-side views of Baseline, Actual, and Diff images.
- Cross-Platform: Works seamlessly with Selenium WebDriver (Web) and Appium (Mobile).
- CI/CD Ready: Integrated with GitHub Actions for automated verification.
Installation
Basic Installation
pip install visual-guard
Full Installation (Recommended)
To enable SSIM comparison, install the extra dependencies:
pip install visual-guard[full]
# OR manually
pip install scikit-image numpy imagehash
Note: On some platforms (e.g., bleeding-edge Python versions), scikit-image may not have pre-built wheels. Visual Guard will gracefully fall back to Pixel/pHash methods if SSIM is unavailable.
Quick Start
Web Automation
from visual_guard import VisualTester
from selenium import webdriver
# 1. Setup Driver
driver = webdriver.Chrome()
driver.get("https://example.com")
# 2. Initialize Visual Guard
visual = VisualTester()
# 3. Compare Full Page (Default: Pixel)
# First run creates the baseline. Subsequent runs compare against it.
visual.assert_matches(driver, "homepage")
# 4. Compare using SSIM (Structural Similarity)
# Useful for handling minor rendering differences across browsers
visual.assert_matches(driver, "homepage_ssim", method="ssim", threshold=0.95)
# 5. Compare using pHash (Perceptual Hash)
# Best for ignoring minor color shifts or anti-aliasing noise
visual.assert_matches(driver, "homepage_phash", method="phash", threshold=5)
Advanced Masking
Ignore dynamic areas to keep tests stable. You can now use Polygons!
# Mask a simple rectangle (x, y, width, height)
# Useful for banners or fixed headers
visual.assert_matches(driver, "dashboard", exclude_regions=[(100, 50, 200, 30)])
# Mask a complex Polygon shape (list of x,y points)
# Useful for irregular shapes, logos, or floating action buttons
visual.assert_matches(driver, "map_view", exclude_regions=[
[(10, 10), (50, 10), (50, 50), (10, 50)] # A custom quad
])
Reporting
Generate a comprehensive visual report to see exactly what changed:
from visual_guard import SimpleReporter
reporter = SimpleReporter()
try:
visual.assert_matches(driver, "homepage")
reporter.add_result("homepage", True, "tests/baselines/homepage.png", "tests/snapshots/homepage.png")
except Exception as e:
reporter.add_result("homepage", False, "tests/baselines/homepage.png", "tests/snapshots/homepage.png", "tests/diffs/homepage_diff.png")
reporter.generate("visual_report.html")
Comparison Methods Guide
| Method | Best For | Threshold | Note |
|---|---|---|---|
| pixel | Icons, Logos, Strict UI elements | 0.0 - 100.0 (Percent diff) | Default. Very sensitive. |
| ssim | Complex layouts, Text blocks | 0.0 - 1.0 (Similarity score) | Requires scikit-image. Best for general UI. |
| phash | Dynamic content, Cross-browser | 0 - 64 (Hamming distance) | Extremely robust to minor pixel shifts. |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file visual_guard-0.2.0.tar.gz.
File metadata
- Download URL: visual_guard-0.2.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee6db311d1e102b42e162109ce6a309a7832c66bfd8d28e33da7b4326913c28d
|
|
| MD5 |
7b5752f06409cfc7e1234665ff3b08cd
|
|
| BLAKE2b-256 |
7ed011f82f0ba70699979a32bd8991d433d2f1af664e4459801e567483c5000f
|
File details
Details for the file visual_guard-0.2.0-py3-none-any.whl.
File metadata
- Download URL: visual_guard-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21716e081e165cea1483d12b85e149fc43e5b40602f7b816f306ac15585d7246
|
|
| MD5 |
f3d2d61f994db4ab239d4aaddb193ae7
|
|
| BLAKE2b-256 |
5d092bca3ba46d6dc910f9d6e6feba1280f9d4076a363d178be4b75df1ea0adf
|