Overview
Detect unintended visual changes by comparing screenshots against baselines. Uses Playwright, Percy, or Chromatic for automated visual regression testing.
Capabilities
- Capture and compare screenshots against baselines
- Detect pixel-level visual regressions
- Manage baselines across branches and environments
- Test responsive layouts at multiple viewport sizes
- Ignore dynamic content (animations, timestamps)
When to Use
Trigger phrases:
"visual regression"
"Visual regression testing — screenshot comparison, baseline management, and UI c"
After UI changes — verify nothing broke visually
CSS refactoring — ensure visual parity
Cross-browser visual consistency checks
Design system component library testing
When NOT to Use
- Task is about deployment, not development (use deploy skills)
- Task is about code review, not writing (use review skills)
- You need to understand existing code first (use research skills)
- Task is about testing only (use test skills)
- Requirements are unclear (clarify first)
- Task is trivially simple (single line fix)
Pseudo Code
The visual-regression workflow follows a standard pipeline pattern.
Core flow:
# visual-regression primary flow
input = prepare(raw_data)
result = process(input, config={baseline, change, comparison, detection, management})
validate(result)
deliver(result)
Error handling:
on error:
log(error_details)
retry_with_backoff(max=3)
if still_failing: alert_and_escalate()
Playwright Visual Test
test('homepage matches baseline', async ({ page }) => {
await page.goto('/')
await expect(page).toHaveScreenshot('homepage.png', {
maxDiffPixelRatio: 0.01,
animations: 'disabled'
})
})
Responsive Visual Test
const viewports = [
{ width: 320, height: 568, name: 'mobile' },
{ width: 768, height: 1024, name: 'tablet' },
{ width: 1440, height: 900, name: 'desktop' }
]
for (const vp of viewports) {
test(`responsive ${vp.name}`, async ({ page }) => {
await page.setViewportSize({ width: vp.width, height: vp.height })
await page.goto('/')
await expect(page).toHaveScreenshot(`${vp.name}.png`)
})
}
Common Patterns
- Baseline per branch: Different baselines for different feature branches
- Ignore regions: Mask dynamic content (ads, timestamps, animations)
- Threshold tuning: 0.01% max diff for strict, 1% for lenient
- Full-page screenshots: Capture full scrollable area, not just viewport
How to Use
- Understand the requirement and existing codebase patterns
- Design the solution with error handling and testability in mind
- Implement incrementally with tests for each change
- Verify against expected outcomes (manual and automated)
- Document usage, edge cases, and integration points
- Review with team before merging to shared branches
Red Flags
- Skipping tests to ship faster: Untested code breaks in production when you least expect it
- No error handling in production code: Unhandled errors crash services and lose user data
- Hardcoded configuration values: Hardcoded values prevent environment switching and leak secrets
- Ignoring security implications: Missing input validation, auth bypasses, and injection vulnerabilities
- Over-engineering simple solutions: Premature abstraction adds complexity without proportional benefit
Verification
Process
- Analyze the task requirements
- Apply domain expertise
- Verify output quality
Anti-Rationalization Table
| Rationalization |
Reality |
| "Tests slow me down" |
Bugs slow you down 10x more. Tests are speed, not overhead. |
| "I will refactor later" |
Technical debt compounds. Refactor as you go. |
| "It works on my machine" |
If it is not in CI, it does not work. Ship proof, not claims. |
1---2name: visual-regression3description: Use when visual regression testing — screenshot comparison, baseline4 management, and UI change detection. Use when working with visual regression.5domain: development6author: oyi777license: Apache-2.08subdomain: software-development9tags:10- coding11- regression12- software-engineering13- testing14- visual15version: 1.0.016category: development17metadata:18 source: https://skillmd.com/skills/oyi77/visual-regression19---20212223## Overview2425Detect unintended visual changes by comparing screenshots against baselines. Uses Playwright, Percy, or Chromatic for automated visual regression testing.2627## Capabilities2829- Capture and compare screenshots against baselines30- Detect pixel-level visual regressions31- Manage baselines across branches and environments32- Test responsive layouts at multiple viewport sizes33- Ignore dynamic content (animations, timestamps)3435## When to Use36**Trigger phrases:**37- "visual regression"38- "Visual regression testing — screenshot comparison, baseline management, and UI c"394041- After UI changes — verify nothing broke visually42- CSS refactoring — ensure visual parity43- Cross-browser visual consistency checks44- Design system component library testing4546## When NOT to Use4748- Task is about deployment, not development (use deploy skills)49- Task is about code review, not writing (use review skills)50- You need to understand existing code first (use research skills)51- Task is about testing only (use test skills)52- Requirements are unclear (clarify first)53- Task is trivially simple (single line fix)545556## Pseudo Code5758The visual-regression workflow follows a standard pipeline pattern.5960Core flow:61```62# visual-regression primary flow63input = prepare(raw_data)64result = process(input, config={baseline, change, comparison, detection, management})65validate(result)66deliver(result)67```6869Error handling:70```71on error:72 log(error_details)73 retry_with_backoff(max=3)74 if still_failing: alert_and_escalate()75```767778### Playwright Visual Test79```typescript80test('homepage matches baseline', async ({ page }) => {81 await page.goto('/')82 await expect(page).toHaveScreenshot('homepage.png', {83 maxDiffPixelRatio: 0.01,84 animations: 'disabled'85 })86})87```8889### Responsive Visual Test90```typescript91const viewports = [92 { width: 320, height: 568, name: 'mobile' },93 { width: 768, height: 1024, name: 'tablet' },94 { width: 1440, height: 900, name: 'desktop' }95]9697for (const vp of viewports) {98 test(`responsive ${vp.name}`, async ({ page }) => {99 await page.setViewportSize({ width: vp.width, height: vp.height })100 await page.goto('/')101 await expect(page).toHaveScreenshot(`${vp.name}.png`)102 })103}104```105106## Common Patterns107108- **Baseline per branch**: Different baselines for different feature branches109- **Ignore regions**: Mask dynamic content (ads, timestamps, animations)110- **Threshold tuning**: 0.01% max diff for strict, 1% for lenient111- **Full-page screenshots**: Capture full scrollable area, not just viewport112113## How to Use1141151. Understand the requirement and existing codebase patterns1162. Design the solution with error handling and testability in mind1173. Implement incrementally with tests for each change1184. Verify against expected outcomes (manual and automated)1195. Document usage, edge cases, and integration points1206. Review with team before merging to shared branches121122## Red Flags123124- **Skipping tests to ship faster**: Untested code breaks in production when you least expect it125- **No error handling in production code**: Unhandled errors crash services and lose user data126- **Hardcoded configuration values**: Hardcoded values prevent environment switching and leak secrets127- **Ignoring security implications**: Missing input validation, auth bypasses, and injection vulnerabilities128- **Over-engineering simple solutions**: Premature abstraction adds complexity without proportional benefit129130## Verification131132- [ ] Skill output matches expected behavior133134## Process1351361. Analyze the task requirements1372. Apply domain expertise1383. Verify output quality139140## Anti-Rationalization Table141142| Rationalization | Reality |143|---|---|144| "Tests slow me down" | Bugs slow you down 10x more. Tests are speed, not overhead. |145| "I will refactor later" | Technical debt compounds. Refactor as you go. |146| "It works on my machine" | If it is not in CI, it does not work. Ship proof, not claims. |