Screenshot Baselines: The Lifecycle of a Visual Test

Screenshot Baselines: The Lifecycle of a Visual Test

In visual testing the baseline image is the assertion itself. The lifecycle: generate in the reference environment, commit next to tests, update scoped, and review like code.

In a visual test the baseline image is the assertion, which makes screenshot baseline management a review discipline rather than housekeeping. The lifecycle has four stages with rules: baselines are generated in the reference environment (never a laptop's host OS), committed to the repository next to their tests, updated as a deliberate scoped act rather than a suite-wide flag, and reviewed image-against-image before merge. Binary baselines cannot be merged by git, so multi-engineer conflicts resolve by rebase, regenerate, re-review — and the discipline's failure mode is not missing baselines but approving them without looking.

A baseline is a reviewed artifact, not a byproduct

Many test artifacts are disposable — logs, coverage reports, traces. The baseline image is the opposite: it is the expectation itself. When a visual assertion runs, the baseline is the entire definition of "correct," and the code contributes nothing to the verdict beyond producing pixels to compare.

That inverts where the quality lives. In a conventional test, correctness is encoded in assertions a reviewer can read in the diff. In a visual test, correctness is whatever the approved image shows — so the moment of approval carries the weight that assertion-writing carries elsewhere. Approving a baseline is defining correctness for that surface: from then on, the suite will defend that image against every future change, including the case where the image itself encoded a defect.

The practical consequence is ownership. Every baseline set should have a clear answer to the question "who judged this correct?" — and on surfaces where design intent and engineering implementation belong to different people, that answer is a convention worth writing down before the first disputed diff, not after. How diffs get judged in review is its own craft, treated separately within this topic; this article stays on the artifact and its lifecycle.

Where baselines are born

A baseline must be generated in the same environment that will later compare against it. This single rule prevents the failure described next.

The canonical version: an engineer writes a visual test on a macOS laptop, runs it once to create the baseline, commits, and pushes. CI — running Linux — captures the same page and fails, and keeps failing forever. If the snapshot path ignores the platform, CI compares its Linux capture against the macOS baseline, and the two differ because macOS and Linux rasterize fonts and anti-alias edges differently. With Playwright's default snapshot names, which include the platform, CI fails for a different reason: there is no Linux baseline to compare against, and by default a test that creates a missing snapshot fails (as of November 2026). No code is wrong. The baseline was simply born on the wrong machine.

The fix follows from the determinism work this topic treats separately: designate one reference rendering environment — in practice the runner's container — and let baselines be born only there. Two workable patterns exist. Either engineers generate baselines locally inside the same container image CI uses, or a CI job regenerates them on demand and commits the result back to the branch. Both are fine; laptops rendering with their host OS are not.

Runners also support intentionally platform-split baselines — Playwright names snapshot files with browser (or project) and platform suffixes by default (as of November 2026), so one test can hold a Linux baseline and a macOS baseline side by side. That is an explicit choice to test two platforms, and it doubles the artifacts to generate, store, and review. It is not a workaround for skipping the reference-environment rule; it is a matrix decision, made consciously.

Storage and versioning

Baselines live in the repository, next to the tests they serve. Playwright's default layout (as of November 2026) puts them in a snapshots directory beside the spec file, and the default is right: co-location is what makes the lifecycle reviewable. A pull request that changes rendering carries its new baselines in the same diff as the causing code, and a reviewer sees cause and effect in one place.

Co-location also means baselines travel with branches. A feature branch that redesigns a component carries that component's new baselines; merging the branch merges the new correctness definition. This is exactly the behavior you want — and it is also what makes conflicts possible, which the next section takes up.

The honest cost is repository weight. Baselines are binary blobs; a suite with hundreds of snapshots across a browser matrix adds real megabytes, and git history never forgets a superseded PNG. Teams feeling that weight have two levers: git LFS moves the binaries out of the object store while preserving the co-located workflow, and commercial review services move baseline storage to their cloud entirely. Both are trade-offs rather than upgrades — LFS adds tooling friction for every contributor, and external storage decouples the baseline from the PR diff that explains it. The default remains plain co-location until the weight actually hurts.

The update workflow

Baselines change legitimately when the product's appearance changed on purpose, or when the team deliberately upgrades the reference environment, since, as Playwright's documentation notes, browser rendering can vary based on the host OS, version, settings, hardware, power source, headless mode, and other factors. The update workflow exists to make those cases easy while keeping every other case loud.

The scoped update is the unit of work. When a change intentionally alters rendering, regenerate only the snapshots that change touches — in Playwright (as of November 2026), scoping the update flag to a file or test rather than the whole suite:

bash
# Scoped: regenerate baselines for one spec, inside the reference container
npx playwright test checkout.spec.ts --update-snapshots

The anti-pattern is the same command without the scope, applied to a red build to make it green. A suite-wide update approves every pending deviation at once — the intended changes and the regressions hiding among them — with no one having looked at a single image. It is the visual-testing equivalent of deleting failing assertions, performed in bulk.

A reviewable update, by contrast, puts three things in front of the reviewer in one pull request: the old baseline, the new baseline, and the code change that explains the difference. If those three do not tell a coherent story — if a baseline changed with no plausible causing code in the diff — that is not noise to approve; it can come from causes such as an environment problem or an unrelated regression riding along, and each of these is worth stopping for.

Baseline conflicts between engineers

Two branches change the rendering of the same surface. Each carries its own new baseline for it. Git can merge code with a three-way algorithm; it cannot merge two PNGs. One branch merges first, and the second now holds a baseline that is both conflicted in git terms and stale in correctness terms.

The resolution is procedural, and convention does more than tooling here: rebase onto the winner, regenerate the affected baselines in the reference environment, and re-review the result — because the correct rendering after both changes may be something neither branch's baseline shows. Treating the conflict as a design question ("what should this surface look like now that both changes exist?") rather than a mechanical merge step is what keeps the artifact meaningful.

There is signal in where conflicts happen. Baselines that churn under multiple engineers at once are often shared surfaces — layout primitives, design-system components — which is useful coverage feedback: it marks the surfaces where visual blast radius concentrates. The design-system article on this topic takes that thread to working depth.

What baseline discipline does not solve

Review fatigue is the failure mode of success. A well-covered suite on an actively developed product produces legitimate baseline churn — every intended redesign of a covered surface is an update to produce and review — and volume is what erodes review quality. When update PRs start merging on trust rather than inspection, the lifecycle is intact on paper and dead in practice. The defenses live upstream, in coverage selection and threshold discipline, both treated in their own articles.

Stale baselines are the quieter problem. A baseline approved a year ago encodes a year-old judgment; if a defect was approved then, the suite has been defending it since. High-traffic surfaces earn an occasional deliberate re-look at the baseline itself — not because the suite is failing, but precisely because it is passing.

And no amount of baseline hygiene compensates for an unstable environment. If the same commit produces different pixels on different runs, the problem is not the artifact or the workflow — it is determinism, the other foundation of this topic, and it comes first. A baseline can only be as trustworthy as the machine that rendered it.

Project Inquiry