How to Snapshot Per Browser and Per Viewport in CI
Playwright names snapshots per project, so defining a project per browser and viewport produces a distinct baseline for each combination.
Declare projects for each browser and viewport in playwright.config.ts; Playwright suffixes snapshot names with the project so each combination has its own baseline.
Steps
- Define a
projectsentry per browser and viewport. - Set
use.viewportanduse.browserNameper project. - Generate baselines for every project.
- Run all projects in CI.
Config
playwright.config.ts
export default defineConfig({
projects: [
{ name: 'chromium-desktop', use: { browserName: 'chromium', viewport: { width: 1280, height: 720 } } },
{ name: 'chromium-mobile', use: { browserName: 'chromium', viewport: { width: 375, height: 667 } } },
{ name: 'firefox-desktop', use: { browserName: 'firefox', viewport: { width: 1280, height: 720 } } },
],
});Gotchas
- Every project multiplies baseline count and CI time; snapshot only the combos that matter.
- Firefox and WebKit render text differently, so expect distinct baselines per browser.
Related guides
How to Choose Component vs Full-Page Visual SnapshotsDecide between component-level snapshots via Storybook and full-page snapshots via Playwright, balancing stab…
How to Handle Cross-OS Rendering Differences in Visual TestsStop cross-OS rendering differences from failing visual tests by generating and comparing baselines inside on…