Skip to main content

A robust visual regression testing library for Python.

Project description

Visual Guard

Visual Guard CI

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


Download files

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

Source Distribution

visual_guard-0.2.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

visual_guard-0.2.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file visual_guard-0.2.1.tar.gz.

File metadata

  • Download URL: visual_guard-0.2.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for visual_guard-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2e379380ce16f41d9b06bea4dbbe5bf31118da8c57f22f7de58b83de9f8dbc90
MD5 8f6a80241c3bb2b1609ac4c93e8a2cd6
BLAKE2b-256 77750a0c485d170ce23249903a0d094fc735dfcd287ae3294c12adaa4fc3d596

See more details on using hashes here.

File details

Details for the file visual_guard-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: visual_guard-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for visual_guard-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f797d47721855349516c152c57993f91bbd7075e38d27949f3f9519f72828bc
MD5 25a25ee1baeec9c7a878bfb6a3109935
BLAKE2b-256 600f8b6ec5af39c555088fd17572785ed6fb194abf9143e7b1c484dd73c56a3b

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