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. |
Metadata
Release files for visual-guard 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| visual_guard-0.2.1.tar.gz | 10.8 kB | Without provenance | Details for visual_guard-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| visual_guard-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for visual_guard-0.2.1-py3-none-any.whl |
Total release size: 20.3 kB
Release files / visual_guard-0.2.1.tar.gz
| Download URL | visual_guard-0.2.1.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e379380ce16f41d9b06bea4dbbe5bf31118da8c57f22f7de58b83de9f8dbc90
|
|
BLAKE2b-256 checksum How to use checksums |
77750a0c485d170ce23249903a0d094fc735dfcd287ae3294c12adaa4fc3d596
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / visual_guard-0.2.1-py3-none-any.whl
| Download URL | visual_guard-0.2.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f797d47721855349516c152c57993f91bbd7075e38d27949f3f9519f72828bc
|
|
BLAKE2b-256 checksum How to use checksums |
600f8b6ec5af39c555088fd17572785ed6fb194abf9143e7b1c484dd73c56a3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for visual-guard 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.