Visual Regression Testing
Sets up and runs visual regression tests to catch unintended UI changes. Captures screenshots of components and pages, compares against baselines, and generates diff reports highlighting pixel-level changes.
Command
/visual-regression
Description
Configures and executes visual regression testing for your frontend application. Takes screenshots of specified pages or components, compares them against approved baselines, and generates a visual diff report showing exactly what changed. Supports Playwright, Puppeteer, and Cypress screenshot backends.
Behavior
-
Setup (first run):
- Detect existing test framework (Playwright, Cypress, Puppeteer)
- Create
visual-tests/directory with baseline and diff folders - Generate config file with viewport sizes and test targets
- Install required dependencies (
pixelmatch,pngjs)
-
Capture -- Take screenshots of all configured pages/components
-
Compare -- Pixel-diff each screenshot against its baseline
-
Report -- Generate an HTML report with side-by-side comparisons
-
Update -- Approve new baselines when changes are intentional
Output Format
Directory Structure
visual-tests/
āāā baselines/ # Approved reference screenshots
ā āāā homepage-desktop.png
ā āāā homepage-mobile.png
ā āāā login-form.png
āāā current/ # Latest test screenshots
āāā diffs/ # Highlighted differences
āāā report.html # Visual comparison report
āāā config.json # Test configuration
Configuration (visual-tests/config.json)
{ "baseUrl": "http://localhost:3000", "threshold": 0.1, "viewports": [ { "name": "desktop", "width": 1280, "height": 720 }, { "name": "tablet", "width": 768, "height": 1024 }, { "name": "mobile", "width": 375, "height": 812 } ], "pages": [ { "name": "homepage", "path": "/", "waitFor": ".hero-section" }, { "name": "login", "path": "/login", "waitFor": "form" }, { "name": "dashboard", "path": "/dashboard", "auth": true } ], "ignore": [ { "selector": ".timestamp", "reason": "Dynamic content" }, { "selector": ".avatar", "reason": "User-specific" } ] }
Test Report Summary
Visual Regression Results:
ā homepage-desktop (0.00% diff)
ā homepage-mobile (0.02% diff)
ā login-form-desktop (3.47% diff) ā diffs/login-form-desktop.png
ā dashboard-desktop (0.00% diff)
1 of 4 tests failed. See report.html for details.
Examples
/visual-regression --setup # First-time configuration
/visual-regression # Run all visual tests
/visual-regression --update-baselines # Approve current as new baseline
/visual-regression --page homepage # Test specific page only
/visual-regression --viewport mobile # Test specific viewport only
/visual-regression --threshold 0.5 # Allow up to 0.5% pixel difference
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.