Prompt
How do I automate screenshots and visual checks for a web app?
Latest observation
Nov 7, 2026
OpenAI APIWeb search: off
Automating screenshots and visual checks for a web app is usually done with end-to-end browser testing plus visual regression testing.
Common approach
1) Use a browser automation tool
Pick one of:
- Playwright (very popular, great for screenshots, cross-browser support)
- Cypress (good for app testing, with visual plugins)
- Selenium (older, broader ecosystem)
Playwright is often the easiest choice for this use case.
2) Capture screenshots of pages/components
You can automate:
- Full page screenshots
- Specific element screenshots
- Screenshots at different viewport sizes
- Screenshots in different states:
- logged in / logged out
- light / dark mode
- mobile / tablet / desktop
- error states, hover states, modal open, etc.
3) Compare screenshots against baselines
A visual regression tool compares new screenshots to stored “golden” images and flags diffs.
Options:
- Playwright built-in snapshot assertions
- Percy
- Applitools
- Chromatic (especially for Storybook)
- Loki / BackstopJS for open-source visual regression
Simple example with Playwright
Install
npm init playwright@latest
Test example
import { test, expect } from '@playwright/test';
test('home page visual check', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot('homepage.png');
});
This will:
- take a screenshot
- compare it to a baseline
- fail if the UI changes beyond an allowed threshold
Best practices for stable visual tests
Make screenshots deterministic
UI tests can be flaky if the page changes slightly each run. To reduce that:
- Freeze time/date
- Mock API responses
- Disable animations and transitions
- Use fixed fonts if possible
- Hide dynamic content like:
- ads
- timestamps
- random IDs
- avatars
- carousels
- Use consistent viewport sizes and device pixel ratios
Test in a clean environment
- Run in CI with the same browser version
- Reset app state before each test
- Use seeded data
Set diff thresholds
Allow small pixel differences from anti-aliasing or rendering changes:
- use a pixel threshold or mismatch percentage
- review diffs before updating baselines
Typical workflow in CI
- Run app tests on every pull request
- Capture screenshots
- Compare against baseline images
- Upload diffs if changed
- Fail the build if differences exceed threshold
- Approve and update baseline screenshots when changes are intentional
Recommended stack
If you want something modern and straightforward:
- Playwright for automation
- Playwright snapshots for basic visual checks
- Percy or Chromatic if you want a polished review workflow in CI
If you want component-level visual testing
If your app uses React/Vue/Svelte and you have Storybook:
- Put each component in Storybook
- Run visual regression on stories
- This is often easier than testing whole pages
Quick recommendation
- Small project / quick start: Playwright screenshot assertions
- Team workflow / PR review: Percy or Chromatic
- Open-source self-hosted: BackstopJS or Loki
If you want, I can give you:
- a Playwright setup for screenshot testing,
- a CI example for GitHub Actions, or
- a tool comparison for Playwright vs Percy vs Chromatic.