Prompt
Why do screenshot tests pass locally but fail in CI?
Latest observation
Nov 24, 2026
OpenAI APIWeb search: off
Screenshot tests often pass locally but fail in CI because the rendering environment is not actually the same. Small differences in browser, OS, fonts, GPU, viewport, timing, or even package versions can change pixels enough to break image comparisons.
Common causes:
-
Different OS / font rendering
- CI often runs Linux, while local dev might be macOS or Windows.
- Font substitution, antialiasing, and text rendering differ.
-
Different browser versions
- Chrome/Chromium version mismatches can shift layout or rendering slightly.
-
Different viewport / device scale factor
- If CI uses a different window size, DPR, or zoom level, screenshots change.
-
Missing fonts or assets in CI
- Custom fonts, icons, or images may not be installed or loaded properly.
-
Timing / async issues
- The page may not be fully loaded, animated, or settled when the screenshot is taken.
- CI is often slower, so race conditions show up there first.
-
Animation / dynamic content
- Timestamps, spinners, skeleton loaders, ads, and random IDs can cause nondeterminism.
-
Different rendering flags / headless mode
- Headless browsers can render slightly differently from headed ones.
-
Environment-specific data
- Locale, timezone, DPI, dark mode, language, and reduced motion settings can all affect output.
How to make them more reliable:
- Pin browser and test dependencies to exact versions.
- Run screenshots in a consistent container/image locally and in CI.
- Install and preload the same fonts in both environments.
- Fix viewport, DPR, locale, timezone, and color scheme.
- Disable animations and hide dynamic elements.
- Wait for the UI to be stable before capturing.
- Use robust screenshot thresholds or diff tolerances if appropriate.
- Compare against CI-like screenshots locally by running tests in Docker or the same runner image.
If you want, I can help you debug a specific screenshot test failure pattern or suggest a stable setup for Playwright/Cypress/Puppeteer.