Prompt
How do I compare screenshots across browsers and viewports in CI?
Latest observation
A good CI setup for screenshot comparison usually has three parts:
- Capture screenshots in multiple browsers/viewports
- Compare against baselines
- Review and approve diffs when they’re intentional
Recommended approach
1) Use a visual regression tool
Common choices:
- Playwright with built-in screenshot assertions
- Cypress + Percy
- Storybook + Chromatic
- Applitools
- Loki / BackstopJS for more custom setups
If you already use Playwright, it’s often the simplest option.
2) Structure your test matrix
Run the same page/component across combinations like:
- Browsers:
chromium,firefox,webkit - Viewports:
mobile,tablet,desktop - Themes/locales if relevant
Example matrix:
- Chrome 128, 375×667
- Chrome 128, 1280×720
- Firefox 128, 1280×720
- Safari/WebKit, 375×667
Keep the matrix small at first, then expand.
3) Use stable rendering settings
To reduce flaky diffs:
- Wait for fonts to load
- Disable animations
- Mock time/randomness
- Stub APIs and network calls
- Use fixed data
- Hide dynamic elements like timestamps/counters
- Set consistent timezone and locale
- Use consistent device scale factor if needed
For Playwright, common settings:
animations: 'disabled'maskdynamic selectorsfullPage: trueonly when needed
4) Save baselines per browser if needed
Browsers render slightly differently, so you may want:
- one baseline per browser
- or one baseline per browser + viewport combination
This depends on how strict you want comparisons to be.
Typical layout:
screenshots/
homepage-chromium-1280.png
homepage-firefox-1280.png
homepage-webkit-375.png
5) Run in CI
Use a CI job matrix to parallelize.
Example with GitHub Actions:
name: visual-tests
on: [push, pull_request]
jobs:
screenshots:
runs-on: ubuntu-latest
strategy:
matrix:
browser: [chromium, firefox, webkit]
viewport: [mobile, desktop]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test --project=${{ matrix.browser }} --grep @visual
env:
VIEWPORT: ${{ matrix.viewport }}
6) Compare and report diffs
Most tools generate:
- actual screenshot
- expected screenshot
- diff image
- HTML report
In CI, publish these as:
- build artifacts
- PR comments
- screenshots in a dashboard
That way reviewers can inspect the visual change before merging.
7) Make approvals explicit
For intentional UI changes:
- update baselines in a separate commit/PR
- require human review before accepting new screenshots
- avoid auto-updating baselines on every run
Example: Playwright screenshot testing
import { test, expect } from '@playwright/test';
test.use({ viewport: { width: 1280, height: 720 } });
test('homepage looks correct', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(page).toHaveScreenshot('homepage.png', {
animations: 'disabled',
});
});
You can parameterize browser/viewports via Playwright projects.
Practical tips
- Start with the most important pages/components only
- Use a dedicated “visual” test suite
- Keep screenshots small and focused
- Don’t compare pages with live ads, chat widgets, or other unstable third-party content
- Use thresholds sparingly; too much tolerance can hide regressions
If you want the easiest production-ready path
- Playwright if you want control and low cost
- Percy/Chromatic if you want collaboration and review tooling
- Applitools if you want more advanced AI-based diffing
If you tell me your stack (Playwright/Cypress/Storybook/GitHub Actions/GitLab/etc.), I can give you a concrete CI config and test example.