QA GLOSSARY · TERM 5 OF 6

Visual regression testing

Visual regression testing compares a screenshot of a page with an approved earlier screenshot, the baseline, and fails when too much of it has changed. The Zong Health Scanner works this way: if more than 0.5% of the page changed, it flags it and saves a difference image that shows exactly where.

Updated 4 December 2026

How it works

  1. Take a screenshot of a page in a known state, and approve it as the baseline.
  2. On every later run, take a new one in the same conditions and compare the two pixel by pixel.
  3. If the changed part is bigger than a threshold, the test fails, and a difference image is saved with the changed pixels marked.
  4. If the change was meant, approve a new baseline. If it was not, fix the page.

It catches what a normal test cannot. A page can still do everything it should and look broken: a button pushed off the screen, text overlapping, a missing image, a layout that falls apart at the width of a phone. It is a kind of regression testing for the look of a page.

The scanner as an example

The Zong Health Scanner was built during a QA automation internship. Each scan is compared with an approved baseline screenshot, pixel by pixel. The threshold is 0.5% of the page. Above it the scan flags the change and saves a difference image. The scanner's interface can also approve a new baseline, which is step four above, done on purpose.

Why there is a threshold

A threshold of zero would fail on differences that are not bugs: how text is smoothed can change a few pixels even on a page that is the same. Too low a threshold gives false alarms, and people stop believing the test. Too high a threshold misses real changes. The Zong scanner uses 0.5%, and the right number for your page is found by looking at what the harmless differences look like.

The same idea in Playwright

Playwright has the idea built in. The first run saves the baseline next to the test, and every later run compares with it. The allowed difference is set as a share of the pixels, so 0.5% is 0.005:

A visual check in Playwright
await expect(page).toHaveScreenshot("services.png", {
  maxDiffPixelRatio: 0.005,   // up to 0.5% of the pixels may differ
  animations: "disabled",     // freeze animations so they do not cause false alarms
  mask: [page.getByTestId("clock")],   // leave out something that always changes
});

Why visual tests turn flaky

A screenshot test fails when the page differs for a reason that is not a bug: an animation caught half way, a date or time on the page, an advert, a font that loads late, or a different machine drawing text slightly differently. The cure is the same as for any flaky test: remove the cause. Freeze the animation, mask the part that changes, wait until the fonts are in, and always take baselines on the same kind of machine that runs the checks.

Questions people ask

What is a baseline?

The approved screenshot that later ones are compared with. It is the answer to "what should this page look like", so it needs to be approved by a person, not just saved.

Does a failing visual test always mean a bug?

No. It means the page changed. Sometimes the change was meant, such as a new design, and the baseline just needs to be approved again. The test cannot tell the two apart; a person decides.

Do I have to save the screenshots in the repository?

Playwright saves them in a folder next to the test, and most teams keep them in the repository so a change to a baseline is reviewed like any other change.

Where the facts come from

See also on this site