Skip to main content

Overview

Visual regression tests capture screenshots of your resources and compare them against saved baselines. This catches unintended visual changes across themes, display modes, and hosts. Screenshot comparisons only run when you pass --visual. Without it, result.screenshot() calls are silently skipped, so you can include them in your regular e2e tests without affecting normal runs.

Running Visual Tests

Writing Visual Tests

Use result.screenshot() in any e2e test. It accepts an optional name and Playwright toHaveScreenshot options:

Screenshot Targets

By default, inspector.renderTool() hides the inspector sidebars, and screenshot() captures the app content inside the double-iframe. This keeps visual baselines stable when the inspector UI changes. Pass a specific element locator to narrow the capture further:

Configuring Visual Defaults

Pass a visual option to defineConfig() to set project-wide defaults for screenshot comparison:
All Playwright toHaveScreenshot options (threshold, maxDiffPixelRatio, maxDiffPixels, animations, etc.) are supported. The snapshotPathTemplate controls where baseline images are stored.

See Also

E2E Testing

Full E2E testing guide with the mcp fixture.

Inspector

The runtime that powers visual tests.