Skip to content
mentoor

Topic 3 of 4 · 4 min read

Visual regression checks for agent changes

Goal: Read a visual regression report for an agent's change and decide which differences are intended and which are regressions.

A visual regression check compares new screenshots with approved baselines, and your job is to sort every difference into intended or regression before anyone approves it. The tool finds the pixels that changed. It cannot tell you whether the change was meant.

Check yourself · 1 of 3

A visual test reports 12 changed screenshots after an agent's change to one button. What should you do first?

Choose one answer

Why it matters

Agents edit shared code. A change to one button style can shift fifty screens, and nobody opens fifty screens by hand. Screenshot tests catch this. But they also produce noise, and a tired reviewer clicks "update all snapshots" and bakes the bug into the new baseline. Playwright, Storybook with its visual testing tools, and hosted services all work the same way: render, compare, show the difference.

How to do it

  1. Know the intent. Read the task. Write one line: "the primary button gets a larger radius." Only differences that match that line are intended.
  2. Open each flagged difference. Look at the baseline, the new image and the highlighted diff. Never approve from the count of changed pixels alone.
  3. Sort each one. Intended (matches the task), regression (changes something nobody asked for), or noise (animation timing, fonts loading, dates, ads, random data).
  4. Fix the noise at the source. Freeze the clock, mask dynamic areas, disable animations, wait for fonts. The Playwright docs describe masking and thresholds for this.
  5. Check what is not in the report. A screen with no screenshot has no protection. Are the states from the previous topic covered?
  6. Approve narrowly. Update only the baselines for intended differences, and say why in the review.

For engineers, a stable test looks like this:

await expect(page).toHaveScreenshot("checkout.png", {
  mask: [page.locator(".order-date")],
  animations: "disabled",
});

Before and after

Weak: 14 diffs reported, reviewer runs "update snapshots", merges.

Fixed: of 14, 3 are the intended radius change, 2 are a clock in a header (masked), 9 are a footer link that moved 4 px on every page. The footer shift is a regression from a shared style, so the change goes back to the agent.

What goes wrong

  • Blanket approval turns the test into a rubber stamp.
  • A threshold set so loose that real shifts pass.
  • Unstable tests that fail randomly, so people stop reading them.
  • Baselines created by the agent in the same change. Someone must approve them.

Examples

One shared style, many diffs

An agent changes a shared heading margin for the blog page. The report flags 22 screens. Six are blog pages, so intended. Sixteen are settings and billing screens where headings now touch the card above. Those are regressions caused by a shared change, found only because the screenshots covered those screens.

Noise that hides a real bug

A test fails daily because a banner shows today's date. The team raises the threshold to stop it. Next week a button moves 6 px and passes. Masking the date would have kept the strict threshold.

Key points

  • A visual regression tool shows what changed; only you can say whether the change was intended.
  • Start from the written intent of the change and sort each difference into intended, regression or noise.
  • Never approve from a pixel count; open the baseline, the new image and the diff for each flagged item.
  • Remove noise at the source by masking dynamic areas, disabling animations and freezing time, rather than ignoring failures.
  • Approve baselines narrowly, and be suspicious when the agent updates snapshots in the same change as the code.

Common mistakes

  • Running update-all-snapshots to make the check green.
  • Raising the pixel threshold instead of fixing flaky areas.
  • Letting the agent create and approve its own new baselines.
  • Assuming a green run means every screen is covered when only a few have screenshots.

Check yourself · 2 of 3

A screenshot differs on every run because a header shows the current time. What is the best fix?

Choose one answer

Check yourself · 3 of 3

Which difference in a report is a regression?

Choose one answer

Practice items, not counted towards your mastery.

Start here