Testing web applications

Visual regression testing: when comparing screenshots makes sense

A functional test can confirm that a button submits a form while missing the banner that now covers it after a CSS change. Visual regression testing fills this gap by comparing the current rendering with an approved reference image, commonly called a baseline. The comparison becomes useful only when the team controls the environment, test data, and approval process.

Why an image difference is not automatically a defect

A changed pixel does not by itself prove that the product is wrong. A live clock, rotating promotion, animation, random avatar, or different font can alter a screenshot even though the application behaves correctly. If these differences appear on every run, the team may start ignoring failures or replacing baselines without reviewing them.

An overly generous tolerance causes the opposite problem. It removes minor noise but may also conceal a shifted button, clipped label, or missing icon. The goal is therefore not to force a perfect match at any cost. It is to create a signal that a person can assess quickly and consistently.

Visual automation is most valuable where appearance is part of the expected result: responsive layouts, shared components, charts, document previews, and meaningful form states. A one-off design assessment still needs human judgement. Our guide to tests that are not worth automating explains where that distinction matters.

How to make visual checks repeatable

Standardise the execution environment. Keep the browser version, operating system, fonts, viewport, and rendering settings consistent. Playwright’s visual comparison documentation notes that the host platform, hardware, settings, and browser mode can all affect rendering. Generate a baseline in the same controlled environment that will perform subsequent comparisons.

Create a deterministic application state. Use known data, locale, time zone, and viewport dimensions. Wait for an observable application state before taking the screenshot rather than sleeping for a fixed interval. You may disable or mask an animation, cursor, or live timestamp when it is outside the purpose of the check. Masking an entire dynamic panel, however, could hide the very problem the test should reveal.

Choose a useful comparison boundary. A full-page image provides context but changes whenever any content on the page moves. Screenshots of stable components or important regions usually identify a difference more precisely. Select browsers according to user data and risk, as you would for a cross-browser testing strategy. Separate platforms may require separate baselines because they do not render identically.

Review baselines as code changes. The first screenshot is not correct merely because a test generated it. A reviewer should inspect its content, data state, and viewport before accepting it. For later changes, compare the expected, actual, and difference images. Update the baseline only after confirming that the visual change is intentional.

Apply tolerances narrowly. A small pixel threshold can accommodate unavoidable rendering noise. One large project-wide threshold weakens every comparison. Remove the source of instability first, then add a local exception only where its purpose is understood and documented.

What a visual test cannot prove

Matching screenshots do not show that a button works, validation rules are correct, or an order was created in the database. They also do not assess the meaning of copy, keyboard operation, or accessibility as a whole. Pair visual comparisons with behavioural assertions and, where appropriate, API-level checks.

A screenshot difference does not have to block every release immediately. It first needs an owner and a review process. The guide to automated tests in CI/CD shows how different signals can run at suitable stages.

What you gain

Next step

Choose three stable, business-critical screens. Run the comparisons repeatedly without changing the application, remove incidental differences, and only then approve the first baselines. Assign a reviewer and agree what should happen when a visual comparison fails.

Related topics

You might also be interested in

Catch bugs before they reach users

End-to-end tests of key scenarios can run automatically in CI/CD to catch bugs before they reach customers.