Visual Regression Tester
Overview
Detect unintended visual changes in UI components by capturing screenshots and comparing them pixel-by-pixel against approved baselines. Supports Playwright visual comparisons, Percy, Chromatic, BackstopJS, and reg-suit.
Prerequisites
- Browser automation tool installed (Playwright, Puppeteer, or Cypress)
- Visual regression library configured (Playwright
toHaveScreenshot, Percy, Chromatic, or BackstopJS)
- Baseline screenshots committed to version control or stored in a cloud service
- Storybook or component playground running for isolated component captures (optional)
- Consistent rendering environment (Docker or CI with fixed OS/fonts/GPU settings)
Instructions
- Identify all UI components and pages requiring visual coverage using Glob to scan component directories and route definitions.
- Create a visual test file for each component or page:
- Navigate to the component URL or Storybook story.
- Wait for all network requests, animations, and lazy-loaded images to complete.
- Set a consistent viewport size (e.g., 1280x720 for desktop, 375x812 for mobile).
- Capture screenshots with deterministic settings:
- Disable animations and transitions (
* { animation: none !important; transition: none !important; }).
- Mask dynamic content (timestamps, random avatars, ads) with CSS overlays.
- Use
fullPage: true for scrollable pages.
- Compare captured screenshots against baselines:
- Configure pixel difference threshold (recommended: 0.1% for component tests, 0.5% for full-page).
- Generate diff images highlighting changed regions.
- Flag tests as failed when differences exceed the threshold.
- For responsive testing, capture at multiple breakpoints:
- Mobile: 375px width
- Tablet: 768px width
- Desktop: 1280px width
- Wide: 1920px width
- Review diff images for each failure and classify as:
- Intentional change: Update the baseline with
--update-snapshots.
- Regression: File a bug with the diff image attached.
- Integrate into CI so visual tests run on every pull request with diff images uploaded as artifacts.
Output
- Screenshot baseline images stored in
__screenshots__/ or equivalent directory
- Diff images highlighting pixel-level changes between baseline and current
- Visual regression test report with pass/fail status per component
- CI artifacts containing all captured, baseline, and diff images
- Responsive coverage matrix showing results across breakpoints
Error Handling
| Error |
Cause |
Solution |
| Anti-aliasing differences across OS |
Font rendering varies between macOS, Linux, and Windows |
Run visual tests in Docker with fixed fonts; use threshold option to allow sub-pixel variance |
| Flaky screenshots from animations |
CSS transitions or JS animations still running at capture time |
Inject prefers-reduced-motion or disable animations via addStyleTag before capture |
| Missing baseline on first run |
No previous screenshot exists to compare against |
Run with --update-snapshots to create initial baselines; commit them to the repository |
| Viewport size mismatch |
Browser chrome or scrollbar width differs between environments |
Use setViewportSize explicitly; hide scrollbars with CSS overflow: hidden |
| Dynamic content causes false failures |
Timestamps, user avatars, or ads change between runs |
Mask dynamic elements with mask option or replace content via page.evaluate |
Examples
Playwright visual regression test:
import { test, expect } from '@playwright/test';
test('homepage matches baseline', async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
await page.addStyleTag({ content: '* { animation: none !important; }' });
await expect(page).toHaveScreenshot('homepage.png', {
maxDiffPixelRatio: 0.001,
fullPage: true,
});
});
BackstopJS scenario configuration:
{
"label": "Login Page",
"url": "http://localhost:3000/login", # 3000: 3 seconds in ms
"selectors": ["document"],
"misMatchThreshold": 0.1,
"viewports": [
{ "label": "phone", "width": 375, "height": 812 }, # 812: 375 = configured value
{ "label": "desktop", "width": 1280, "height": 720 } # 1280: 720 = configured value
]
}
Resources
Source: jeremylongshore/claude-code-plugins-plus-skills → skills/.curated/testing-visual-regression/SKILL.md
Also appears in: jeremylongshore/claude-code-plugins-plus-skills/plugins/testing/visual-regression-tester/skills/testing-visual-regression/SKILL.md
1---2name: testing-visual-regression3description: 'Detect visual changes in UI components using screenshot comparison. Use when detecting unintended UI changes or pixel differences. Trigger with phrases like "test visual changes", "compare screenshots", or "detect UI regressions". '4---56# Visual Regression Tester78## Overview910Detect unintended visual changes in UI components by capturing screenshots and comparing them pixel-by-pixel against approved baselines. Supports Playwright visual comparisons, Percy, Chromatic, BackstopJS, and reg-suit.1112## Prerequisites1314- Browser automation tool installed (Playwright, Puppeteer, or Cypress)15- Visual regression library configured (Playwright `toHaveScreenshot`, Percy, Chromatic, or BackstopJS)16- Baseline screenshots committed to version control or stored in a cloud service17- Storybook or component playground running for isolated component captures (optional)18- Consistent rendering environment (Docker or CI with fixed OS/fonts/GPU settings)1920## Instructions21221. Identify all UI components and pages requiring visual coverage using Glob to scan component directories and route definitions.232. Create a visual test file for each component or page:24 - Navigate to the component URL or Storybook story.25 - Wait for all network requests, animations, and lazy-loaded images to complete.26 - Set a consistent viewport size (e.g., 1280x720 for desktop, 375x812 for mobile).273. Capture screenshots with deterministic settings:28 - Disable animations and transitions (`* { animation: none !important; transition: none !important; }`).29 - Mask dynamic content (timestamps, random avatars, ads) with CSS overlays.30 - Use `fullPage: true` for scrollable pages.314. Compare captured screenshots against baselines:32 - Configure pixel difference threshold (recommended: 0.1% for component tests, 0.5% for full-page).33 - Generate diff images highlighting changed regions.34 - Flag tests as failed when differences exceed the threshold.355. For responsive testing, capture at multiple breakpoints:36 - Mobile: 375px width37 - Tablet: 768px width38 - Desktop: 1280px width39 - Wide: 1920px width406. Review diff images for each failure and classify as:41 - **Intentional change**: Update the baseline with `--update-snapshots`.42 - **Regression**: File a bug with the diff image attached.437. Integrate into CI so visual tests run on every pull request with diff images uploaded as artifacts.4445## Output4647- Screenshot baseline images stored in `__screenshots__/` or equivalent directory48- Diff images highlighting pixel-level changes between baseline and current49- Visual regression test report with pass/fail status per component50- CI artifacts containing all captured, baseline, and diff images51- Responsive coverage matrix showing results across breakpoints5253## Error Handling5455| Error | Cause | Solution |56|-------|-------|---------|57| Anti-aliasing differences across OS | Font rendering varies between macOS, Linux, and Windows | Run visual tests in Docker with fixed fonts; use `threshold` option to allow sub-pixel variance |58| Flaky screenshots from animations | CSS transitions or JS animations still running at capture time | Inject `prefers-reduced-motion` or disable animations via `addStyleTag` before capture |59| Missing baseline on first run | No previous screenshot exists to compare against | Run with `--update-snapshots` to create initial baselines; commit them to the repository |60| Viewport size mismatch | Browser chrome or scrollbar width differs between environments | Use `setViewportSize` explicitly; hide scrollbars with CSS `overflow: hidden` |61| Dynamic content causes false failures | Timestamps, user avatars, or ads change between runs | Mask dynamic elements with `mask` option or replace content via `page.evaluate` |6263## Examples6465**Playwright visual regression test:**6667```typescript68import { test, expect } from '@playwright/test';6970test('homepage matches baseline', async ({ page }) => {71 await page.goto('/');72 await page.waitForLoadState('networkidle');73 await page.addStyleTag({ content: '* { animation: none !important; }' });74 await expect(page).toHaveScreenshot('homepage.png', {75 maxDiffPixelRatio: 0.001,76 fullPage: true,77 });78});79```8081**BackstopJS scenario configuration:**8283```json84{85 "label": "Login Page",86 "url": "http://localhost:3000/login", # 3000: 3 seconds in ms87 "selectors": ["document"],88 "misMatchThreshold": 0.1,89 "viewports": [90 { "label": "phone", "width": 375, "height": 812 }, # 812: 375 = configured value91 { "label": "desktop", "width": 1280, "height": 720 } # 1280: 720 = configured value92 ]93}94```9596## Resources9798- Playwright visual comparisons: https://playwright.dev/docs/test-snapshots99- Percy visual testing: https://www.percy.io/100- Chromatic (Storybook): https://www.chromatic.com/101- BackstopJS: https://github.com/garris/BackstopJS102- reg-suit visual regression: https://reg-viz.github.io/reg-suit/103104---105106**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `skills/.curated/testing-visual-regression/SKILL.md`107108**Also appears in:** `jeremylongshore/claude-code-plugins-plus-skills/plugins/testing/visual-regression-tester/skills/testing-visual-regression/SKILL.md`