# Visual regression testing for Puppeteer

> Add visual regression testing to Puppeteer with @snapvisor/puppeteer: capture stable screenshots, upload them with the CLI in CI and review diffs on PRs.

Source: https://snapvisor.io/puppeteer

Guide

Keep your Puppeteer scripts. @snapvisor/puppeteer adds an argosScreenshot call that stabilizes the page and saves a screenshot, and one CLI command uploads the folder. Snapvisor compares each screenshot with the approved baseline and posts the result as a status check on your pull request.

## Install the packages

`@snapvisor/puppeteer` is the Puppeteer adapter and `@snapvisor/cli` uploads the screenshots it saves. The `@snapvisor` packages are drop-in forks of the upstream SDKs and keep the `ARGOS_*` environment variable names on purpose, so a pipeline already wired for the upstream SDKs works unchanged.

shell

```
npm install --save-dev @snapvisor/puppeteer @snapvisor/cli
```

Create a project in the Snapvisor app and copy its project token (`ARGOS_TOKEN`) from the project settings. Store it as a CI secret, never in the repository.

## Capture screenshots in your script

your Puppeteer script

```
import puppeteer from "puppeteer";
import { argosScreenshot } from "@snapvisor/puppeteer";

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("http://localhost:3000");
await argosScreenshot(page, "homepage");
await browser.close();
```

`argosScreenshot` stabilizes the UI before it captures, unless you set `stabilize: false`. It builds on Puppeteer's own screenshot options and adds a few of its own.

- **Viewports.** `viewports` captures the page at more than one viewport size (example below).
- **Extra CSS.** `argosCSS` applies CSS during the screenshot process.
- **Sensitivity.** `threshold` runs from 0 to 1; the higher it is, the less sensitive the diff.
- **Tags.** `tag` attaches one tag or several to the screenshot.

viewports

```
await argosScreenshot(page, "homepage", {
  viewports: [
    { width: 375, height: 812 },
    { width: 1280, height: 800 },
  ],
});
```

## Upload with the CLI

Unlike the Playwright reporter and the Cypress task, the Puppeteer adapter does not upload by itself. It saves the screenshots locally, in `./screenshots/argos`, and you upload that folder with the CLI, usually as the last step of the CI job.

shell

```
export ARGOS_TOKEN="<your project token>"
npx @snapvisor/cli upload ./screenshots/argos
```

`upload` exits `0` once the build has been created, whether or not it contains changes. A non-zero exit means the upload itself failed, for example a bad token, an unresolvable commit or a network error.

## Run it in CI

Run your script, then the upload step. The token comes from the environment.

GitHub Actions

```
- run: npm run build
- run: node screenshots.mjs # your Puppeteer script, captures via argosScreenshot
- run: npx @snapvisor/cli upload ./screenshots/argos
  env:
    ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
```

A green CI job after the upload means the screenshots arrived, not that they are unchanged. The gate is the status check Snapvisor posts to the pull request, so require it in your branch protection rules.

On GitHub Actions you can skip the token with tokenless authentication. Large suites can shard their uploads across CI jobs and be reviewed as one build.

Read more: [GitHub tokenless authentication](https://snapvisor.io/docs/learn/integrations/github-tokenless-authentication), [Parallel testing](https://snapvisor.io/docs/parallel-testing), [GitHub](https://snapvisor.io/docs/github), [GitLab](https://snapvisor.io/docs/gitlab), [Review workflow](https://snapvisor.io/docs/review-workflow).

## What the first build does

The first build on your base branch has nothing to compare against, so it becomes the baseline and is approved automatically. Run it on a base branch that already looks right. Later builds are diffed against the last approved build on the base branch, and approving a change promotes it to the new baseline for that branch.

Read more: [Baseline builds](https://snapvisor.io/docs/baseline-build), [Flaky test detection](https://snapvisor.io/docs/flaky-test-detection).

## Frequently asked questions

### Does Snapvisor support Puppeteer?

Yes. The Snapvisor documentation lists Puppeteer among the official adapters, and the package is @snapvisor/puppeteer. It exports argosScreenshot, which you call with your Puppeteer page.

### Do I have to rewrite my Puppeteer scripts?

No. You keep your script and add an argosScreenshot call wherever you want a screenshot compared, then upload the saved folder with the CLI.

### Why is there a separate upload step?

The Puppeteer adapter saves the screenshots locally and does not upload them itself, unlike the Playwright reporter and the Cypress task. The package saves them in ./screenshots/argos; upload that folder with npx @snapvisor/cli upload ./screenshots/argos, usually at the end of the CI job.

### Which environment variable holds the token?

ARGOS_TOKEN, your project token. The @snapvisor packages keep the ARGOS_ variable names on purpose so pipelines wired for the upstream SDKs work unchanged. On GitHub Actions you can skip the token with tokenless authentication.

### Does a green CI job mean nothing changed?

No. It means the screenshots arrived. The gate is the status check Snapvisor posts to the pull request, so require that check in branch protection.

## Where to go next

[**Visual regression testing in GitHub pull requests**What appears on the pull request and how a reviewer clears it.](https://snapvisor.io/visual-regression-testing-github) [**Visual regression testing guide**How the capture, compare and review loop works.](https://snapvisor.io/visual-regression-testing)

## Sources

Every command, package name and option on this page comes from the Snapvisor documentation and the published `@snapvisor` packages:

- [SDKs](https://snapvisor.io/docs/sdks)
- [Getting started](https://snapvisor.io/docs/getting-started)
- [CI integration](https://snapvisor.io/docs/ci-integration)
- [Baseline builds](https://snapvisor.io/docs/baseline-build)
- [Review workflow](https://snapvisor.io/docs/review-workflow)
- [Parallel testing](https://snapvisor.io/docs/parallel-testing)

## Try Snapvisor free

[Start free](https://app.snapvisor.io/signup) [Getting started guide](https://snapvisor.io/docs/getting-started) [All SDKs](https://snapvisor.io/docs/sdks) [See pricing](https://snapvisor.io/pricing)

## Related pages

Guides [How visual regression testing works](https://snapvisor.io/visual-regression-testing) [Self-hosted visual regression testing](https://snapvisor.io/self-hosted-visual-regression-testing) [Visual regression testing in GitHub pull requests](https://snapvisor.io/visual-regression-testing-github) [Snapvisor MCP server](https://snapvisor.io/mcp)

Test runner and CI setup [Playwright visual testing setup](https://snapvisor.io/playwright) [Storybook visual testing setup](https://snapvisor.io/storybook) [Cypress visual testing setup](https://snapvisor.io/cypress) [Visual regression testing in GitLab CI](https://snapvisor.io/gitlab-ci)

Compare Snapvisor [Snapvisor vs Percy](https://snapvisor.io/compare/percy) [Snapvisor vs Chromatic](https://snapvisor.io/compare/chromatic) [Snapvisor vs Applitools](https://snapvisor.io/compare/applitools) [Snapvisor vs Argos](https://snapvisor.io/compare/argos) [Snapvisor vs Lost Pixel](https://snapvisor.io/compare/lost-pixel) [Snapvisor vs Happo](https://snapvisor.io/compare/happo) [Snapvisor vs Playwright snapshots](https://snapvisor.io/compare/playwright) [Visual regression testing pricing compared](https://snapvisor.io/visual-regression-testing-pricing) [Alternatives to other visual testing tools](https://snapvisor.io/alternatives)

Free tools [Image diff checker](https://snapvisor.io/tools/image-diff) [Screenshot calculator](https://snapvisor.io/tools/screenshot-calculator)
