Skip to main content

Visual regression testing with LLM-powered semantic analysis

Project description

VisualQE

Visual regression testing with LLM-powered semantic analysis.

VisualQE combines traditional pixel-based visual regression testing with Visual Language Models (VLMs) to provide:

  • Reliable change detection via SSIM and pixel diff algorithms
  • Semantic analysis that explains what changed in human terms
  • Intent validation to verify if intended changes were implemented
  • Internal environment testing via Pixcap VPN connector

Installation

pip install visualqe

Or with development dependencies:

pip install visualqe[dev]

Quick Start

Basic Usage

from visualqe import VisualQE

# Initialize with API keys (or set PIXCAP_API_KEY and GEMINI_API_KEY env vars)
vqe = VisualQE(
    pixcap_api_key="your-pixcap-key",
    gemini_api_key="your-gemini-key",  # Optional, for AI analysis
)

# Capture and save a baseline
screenshot = vqe.capture("https://example.com")
vqe.save_baseline("homepage", screenshot)

# Later, compare against the baseline
new_screenshot = vqe.capture("https://example.com")
result = vqe.compare("homepage", new_screenshot)

# Check results
print(f"Changes detected: {result.has_changes}")
print(f"Diff percentage: {result.diff_percentage:.2%}")

# AI analysis (if Gemini key provided)
if result.analysis:
    print(f"Summary: {result.analysis.summary}")
    for change in result.analysis.changes:
        print(f"  - {change.type.value}: {change.element}")

Intent Validation

Verify that intended changes were implemented:

result = vqe.compare(
    "checkout-page",
    new_screenshot,
    intent="The 'Buy Now' button should now be green instead of blue"
)

if result.intent_validated:
    print("Change implemented correctly!")
else:
    print(f"Issue: {result.intent_explanation}")

Internal/Staging Environments

Use the VPN connector to test internal applications:

# Capture internal dashboard (requires Pixcap VPN connector setup)
screenshot = vqe.capture(
    "https://internal.company.com/dashboard",
    use_vpn_connector=True,
)

pytest Integration

# test_visual.py
def test_homepage_visual(visual_check):
    """Test that homepage hasn't changed visually."""
    visual_check("homepage", "https://example.com")

def test_login_page(visual_check):
    """Test login page with intent validation."""
    visual_check(
        "login",
        "https://example.com/login",
        intent="Login form should show 'Remember me' checkbox",
    )

Run tests:

# Set environment variables
export PIXCAP_API_KEY="your-key"
export GEMINI_API_KEY="your-key"  # Optional

# Run visual tests
pytest tests/visual/ --visual-report=./reports/visual.html

# Update baselines (when changes are intentional)
pytest tests/visual/ --visual-update-baselines

CLI Usage

# Capture a screenshot
visualqe capture https://example.com -o screenshot.png

# Compare against baseline
visualqe compare homepage https://example.com --report report.html

# List baselines
visualqe list --baseline-dir ./baselines

# Estimate costs
visualqe estimate 100

# Health check
visualqe health

Configuration

Environment Variables

Variable Description
PIXCAP_API_KEY Pixcap API key for screenshot capture
GEMINI_API_KEY Google Gemini API key for AI analysis

pytest Options

Option Description
--visual-baseline-dir Directory for baselines (default: ./baselines)
--visual-report Path for HTML report
--visual-report-json Path for JSON report
--visual-update-baselines Update baselines instead of comparing
--visual-threshold Diff threshold (default: 0.01 = 1%)
--visual-skip-analysis Skip VLM analysis
--visual-branch Branch name for baseline versioning

Features

Screenshot Capture

  • Public and internal URL support
  • Configurable viewport (320-3840px width)
  • Full-page capture
  • Cookie injection for authenticated pages
  • Element blocking via CSS selectors
  • Dark mode emulation

Diff Algorithms

  • Pixel diff: Fast, precise pixel-by-pixel comparison
  • SSIM: Perceptual similarity aligned with human vision
  • Combined: SSIM for detection, pixel for visualization (default)

VLM Analysis

  • Natural language change summaries
  • Structured change detection with severity levels
  • Intent validation for intentional changes
  • Accessibility analysis

Reporting

  • HTML reports with side-by-side comparison
  • JSON output for CI/CD integration
  • Diff visualization

API Reference

VisualQE

Main class for visual regression testing.

vqe = VisualQE(
    pixcap_api_key: str = None,      # Pixcap API key
    gemini_api_key: str = None,      # Gemini API key
    baseline_dir: str = "./baselines",
    diff_threshold: float = 0.01,    # 1% threshold
)

Methods

  • capture(url, **kwargs) - Capture a screenshot
  • save_baseline(name, screenshot) - Save as baseline
  • compare(name, screenshot, **kwargs) - Compare against baseline
  • capture_and_compare(name, url, **kwargs) - Capture and compare in one call
  • analyze_accessibility(screenshot) - Analyze for accessibility issues

ComparisonResult

Result from a comparison.

result.has_changes        # bool: Whether changes were detected
result.diff_percentage    # float: Percentage of pixels changed
result.diff_image         # PIL.Image: Visual diff
result.analysis           # Analysis: VLM analysis (if enabled)
result.intent_validated   # bool: Whether intent was validated
result.intent_explanation # str: Explanation of validation
result.to_json()          # str: JSON representation

Cost Estimation

Approximate costs per 1,000 comparisons:

Component Cost
Pixcap screenshots (2 per comparison) ~$10-20
Gemini analysis ~$2-5
Total ~$12-25

Use VisualQE.estimate_cost(num_comparisons) or visualqe estimate <count> for estimates.

Architecture

visualqe/
├── capture/          # Screenshot providers (Pixcap)
├── diff/             # Diff algorithms (Pixel, SSIM)
├── analysis/         # VLM providers (Gemini)
├── baseline/         # Baseline storage (Local)
├── reporting/        # Report generators (HTML, JSON)
├── core.py           # Main VisualQE class
└── pytest_plugin.py  # pytest integration

Development

# Clone and install
git clone https://github.com/yourorg/visualqe
cd visualqe
pip install -e ".[dev]"

# Run tests
pytest

# Type checking
mypy src/visualqe

# Linting
ruff check src/
ruff format src/

License

MIT License - see LICENSE file for details.

Acknowledgments

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

visualqe-0.1.1.tar.gz (51.8 kB view details)

Uploaded Source

Built Distribution

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

visualqe-0.1.1-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

Details for the file visualqe-0.1.1.tar.gz.

File metadata

  • Download URL: visualqe-0.1.1.tar.gz
  • Upload date:
  • Size: 51.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for visualqe-0.1.1.tar.gz
Algorithm Hash digest
SHA256 905e8e64c262f95507d2ae370b40bf94b24532491d802352a2b14d6e1076c906
MD5 98e86b04b362bbfb7451adfe2348cac3
BLAKE2b-256 0f07c8c3cfcd19ae9e8ed181342ec64ccafb76e2bccfc7244e33babbc9bebe36

See more details on using hashes here.

File details

Details for the file visualqe-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: visualqe-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for visualqe-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af3e06789a94f1e381b0a500e793e1bc2f4928ba753601ce1653b0bbcc926a57
MD5 2a6c5032aca54055e26163eb3b88866e
BLAKE2b-256 0fd9a89699ae7724fd5e67141615e6f335bf1175ae01ea11e9051365111c4f6d

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