Prompt
I need visual regression testing that scales to hundreds of states
Latest observation
To make visual regression testing scale to hundreds of states, the key is to stop thinking in terms of “one screenshot per page” and instead build a state-driven, automated visual matrix with strong deduplication and prioritization.
A scalable approach
1. Define states explicitly
Model each UI as a set of parameters:
- viewport size
- theme
- locale
- auth/role
- data density
- feature flags
- interaction state
- browser/device
Then generate test cases from combinations of those parameters, but don’t brute-force everything.
2. Use a state matrix with pruning
Create a matrix of representative states, not every possible permutation.
Example:
- 3 viewports × 2 themes × 3 locales × 4 component variants = 72 states
Then apply rules:
- only test valid combinations
- collapse equivalent states
- exclude low-value duplicates
- mark critical vs optional states
3. Automate screenshot generation
Use a test runner like:
- Playwright
- Cypress
- Puppeteer
Generate screenshots programmatically from the matrix.
4. Centralize baselines
Store baselines in version control or object storage with:
- stable naming
- metadata tags
- component/state hashes
- revision history
This makes it easier to update and compare hundreds of images.
5. Add perceptual diffing
Use image diff tools that support:
- threshold tuning
- anti-aliasing handling
- ignore regions
- masking dynamic content
Examples:
- Playwright screenshot assertions
- Percy
- Chromatic
- Applitools
- Loki
6. Detect only meaningful changes
Mask or freeze:
- timestamps
- random IDs
- ads
- avatars
- live data
- animations
Otherwise you’ll drown in false positives.
7. Prioritize by risk
Not all states need equal coverage. Rank by:
- user traffic
- revenue impact
- historical bug frequency
- complexity
- recent changes
Run a smaller “smoke” set on every PR and a larger set nightly.
8. Separate component and page testing
Use two layers:
- Component visual tests for combinatorial state coverage
- Page-level tests for integration and layout interactions
This keeps the system manageable.
9. Use parallelization
Hundreds of screenshots can be expensive, so run:
- in parallel across workers
- sharded by state group
- on CI with caching
10. Make failure triage fast
For scale, the hardest part is reviewing diffs. Build a workflow with:
- grouped diff reports
- automatic clustering of similar failures
- approved baseline updates
- change summaries linked to commits
Recommended architecture
A good scalable setup looks like this:
- State generator: produces valid test cases from a matrix
- Test runner: opens app and captures screenshots
- Diff service: compares against baselines
- Review UI: approves/rejects changes
- Metadata store: tracks state, version, and test history
Practical rule of thumb
If you have hundreds of states:
- keep critical PR checks under ~20–50 screenshots
- run the full matrix nightly or on release branches
- use risk-based sampling for the rest
Best tools depending on needs
- Simple + code-first: Playwright
- Managed + scalable review: Percy / Chromatic / Applitools
- Open-source + component-heavy: Loki + Storybook
If you want, I can give you:
- a reference architecture,
- a Playwright-based implementation, or
- a state matrix design template for your app.