Prompt
Need screenshot diffing in CI
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
For screenshot diffing in CI, the usual approach is:
- Generate screenshots in the test run
- Compare them against checked-in “baseline” images
- Upload diffs/artifacts on failure
- Fail the CI job if the diff exceeds a threshold
Common tools
Depending on your stack:
- Playwright: built-in screenshot assertions
- Cypress:
cypress-image-snapshot - Puppeteer:
jest-image-snapshotor custom pixel diff - Generic image diff:
pixelmatch,looks-same
Good CI setup pattern
- Store baseline screenshots in the repo
- Run tests in a fixed viewport and theme
- Use deterministic fonts, time, locale, and animations disabled
- Save:
- actual screenshot
- expected screenshot
- diff image
- Mark build as failed if diffs are above threshold
Example with Playwright
await expect(page).toHaveScreenshot('home.png', {
maxDiffPixelRatio: 0.01,
});
Then in CI:
npx playwright test
Playwright automatically:
- compares against baseline
- writes diff artifacts
- fails on mismatch
Tips to reduce flaky diffs
- Disable animations
- Wait for network idle or stable UI
- Use consistent viewport size
- Pin browser version in CI
- Use the same OS/font stack if possible
- Mask dynamic regions like timestamps/ads
- Prefer
maxDiffPixelRatioover exact match
If you want full custom diffing
A simple Node setup:
- take screenshots
- compare with
pixelmatch - output a diff PNG
- upload artifacts from CI
If you want, I can give you a ready-to-use CI config for:
- GitHub Actions
- GitLab CI
- Jenkins
- Playwright
- Cypress