How to run a visual regression test with Playwright
A visual regression test compares a fresh screenshot with an approved baseline. Set a fixed viewport, stable data and a ready state so differences reflect changes a user could see.
Skaybase
Choose a small, stable screenshot
Begin with a component or an important page state, such as a filled-out checkout sidebar. Wait for the intended content and fonts. Freeze test data, time-sensitive content and animations where appropriate.
Use the same browser, fonts and operating system for baseline generation and comparison. Choose a meaningful mobile viewport for features that people use on phones.
Example assertion for a review sidebar
This assumes the sidebar exposes that accessible name and the approved fixture shows the text. Playwright can capture expected, actual and diff images when a comparison fails.
const summary = page.getByRole('region', { name: 'Order summary' });
await expect(summary.getByText('Ready for payment')).toBeVisible();
await expect(summary).toHaveScreenshot('order-summary.png');Review the difference before accepting it
- If a button moved below the viewport, file an issue with the viewport and the exact state.
- If the change was intended, regenerate the baseline as part of the reviewed change.
- If the only differences are from unstable test data or missing fonts, stabilize the fixture before widening thresholds.
- Keep a functional assertion alongside the screenshot when behavior matters.