Learn

Running in CI

Artifacts, sharding, merging results from several machines, reporting on the pull request and keeping the bill down.

Visual tests in CI differ from other tests in two ways: they produce files that a human must see and they are sensitive to the machine they run on. Both shape the pipeline.

Run in the pinned environment

The CI job should run the comparison in the same container image that produced the baselines (why). In GitHub Actions that is a container: option on the job or a Docker step. The same applies in other platforms.

Keep the images

A failed comparison leaves actual and diff images on the runner's disk, which disappears with the job. Upload them as an artifact so a reviewer can see them: actions/upload-artifact on GitHub, artifacts: in GitLab, the equivalent elsewhere. Uploading always is simpler and lets you inspect passing runs, but uploading only on failures is an option when you want to keep your artifact size small. Remember to include the baseline too, so the three images travel together and include the manifest if the tool writes one, so the artifact describes itself.

A good artifact is self-contained: unpack it anywhere and a viewer (the one on this site, Playwright's HTML report, BackstopJS's report) can show the run.

With hosted services this part is simpler. Instead of downloading and investigating CI artifact, the reviewer get a link to the service website. There the failing images can be seen, reviewed and approved/rejected.

You can use our viewer to easily work with visual regression screenshots. The demo below lets you create a sample CI artifact and open it directly in the viewer:

The demo renders the run in your browser; enable JavaScript to try it.

Shard and merge

Large suites run across several machines and each machine produces its own images and results. The reporting step then needs to merge them. Playwright's --shard with merge-reports, Vitest's sharding with its blob reporter, Cypress parallelization through a dashboard service all handle their own results. A visual review step on top of them has to read every shard's output. This is the case the manifest was designed for: one file per writer, named visual-regression-manifest.<label>.json, found with one glob across artifacts from every machine and merged with mergeManifests util.

Report on the pull request

Failing the job does not show the reviewer what changed. They need to see the diffs without leaving the PR. Options, cheapest first:

  1. A job summary ($GITHUB_STEP_SUMMARY on GitHub) with the failed screenshot names and the artifact link.
  2. A PR comment with the counts and, where the images are reachable, the baseline, actual and diff inline. Images in comments need a URL, which means uploading them somewhere public or using the artifact's download link.
  3. A check run with annotations per failed screenshot and a button that approves. This is what the hosted services and GitHub Apps provide.
  4. The service's UI, linked from a status check, for tools with service-side baselines.

If your tool writes CTRF or a manifest (which converts to CTRF), the existing CTRF GitHub Actions post summaries and comments without any custom code. There are also services like pixsame which provides you with GitHub Actions customized for handling of the visual regression process.

Approve from CI

With repository baselines, the approval has to end as a commit. Two patterns work well:

  • A workflow triggered by a PR comment (/approve-visuals), which downloads the artifact, copies the approved actual images over their baselines and pushes to the PR branch.
  • An app that does the same after clicking a button on the check.

Keep it fast and cheap

  • Run visual tests on PRs, not on every push to every branch, unless they are fast (e.g. when screenshots are small).
  • Screenshot components rather than whole pages where you can: smaller images, faster diffs, more precise failures.
  • Cache the browser binaries and the renderer image.
  • Compare locally in the runner before uploading anything. And when the artifact gets big: upload only the failures' images.
  • For hosted services billed per screenshot, screenshot once per PR, not once per push and skip the run when only backend code changed.

Further reading

Next

To choose a tool, see the comparison.