How to run Argos visual tests on Vercel preview deployments

Run Playwright visual tests against every Vercel preview from GitHub Actions. Argos compares the screenshots and links the preview to the build.

Greg BergéCo-founder and CEO
· Updated

Run your Playwright visual tests against the Vercel preview of each pull request, from GitHub Actions. Argos compares the screenshots with your baseline and links the preview to the build, so each screenshot opens on the same page of the preview.

Abstract illustration of a deployment branching into a preview panel that feeds a visual comparison

Why test the preview

  • One build. Vercel already built your app. CI only runs the tests, against the deployment your reviewers open.
  • The real deployment. Your tests see the app as Vercel serves it, with its preview environment variables and configuration, not a local server.
  • The preview on the build. Argos detects the preview your tests ran on and shows it on the build page and in the pull request comment.

Keep these tests read-only. They run against a real deployment and its data, so a test that deletes a user or places an order changes what the next run sees.

Prerequisites

1. Create an Argos project

Sign up to Argos, import your repository and copy its project token. Store it as the ARGOS_TOKEN secret of your GitHub repository.

Argos links the preview only to builds that authenticate with a project token or GitHub Actions OIDC. Builds that use tokenless authentication skip it.

2. Install the Argos Playwright SDK

npm install --save-dev @argos-ci/playwright

3. Configure Playwright

Add the Argos reporter, which uploads the screenshots at the end of the run, and read the base URL from BASE_URL, which CI sets to the preview URL:

// playwright.config.ts
import { defineConfig } from "@playwright/test";
import { createArgosReporterOptions } from "@argos-ci/playwright/reporter";

export default defineConfig({
  reporter: [
    // Use "dot" reporter on CI, "list" otherwise (Playwright default).
    process.env.CI ? ["dot"] : ["list"],
    [
      "@argos-ci/playwright/reporter",
      // Upload only on CI.
      createArgosReporterOptions({ uploadToArgos: !!process.env.CI }),
    ],
  ],
  use: {
    // The preview URL on CI, your local server otherwise.
    baseURL: process.env.BASE_URL ?? "http://localhost:3000",
    extraHTTPHeaders: {
      // Keep the Vercel Toolbar out of screenshots.
      "x-vercel-skip-toolbar": "1",
    },
    // Reduce text rendering differences between machines.
    launchOptions: {
      args: ["--disable-lcd-text", "--font-render-hinting=none"],
    },
  },
});

Vercel can add its toolbar to previews. The x-vercel-skip-toolbar header keeps it out of your screenshots (Vercel docs).

If your previews use Deployment Protection

A protected preview answers your tests with a sign-in page. Generate a secret under Protection Bypass for Automation in your Vercel project, store it as the VERCEL_AUTOMATION_BYPASS_SECRET secret of your repository, and send it with every request:

extraHTTPHeaders: {
  "x-vercel-skip-toolbar": "1",
  ...(process.env.VERCEL_AUTOMATION_BYPASS_SECRET
    ? {
        "x-vercel-protection-bypass":
          process.env.VERCEL_AUTOMATION_BYPASS_SECRET,
        // Recommended by Vercel for in-browser tests.
        "x-vercel-set-bypass-cookie": "true",
      }
    : {}),
},

4. Take screenshots of your pages

Loop over the pages to cover, one test each (Capture screenshots from URLs):

// tests/screenshot-pages.spec.ts
import { argosScreenshot } from "@argos-ci/playwright";
import { test } from "@playwright/test";

const pages = [
  { name: "homepage", path: "/" },
  { name: "pricing", path: "/pricing" },
];

for (const { name, path } of pages) {
  test(`Run Argos on ${name} (${path})`, async ({ page }) => {
    await page.goto(path);
    await argosScreenshot(page, name);
  });
}

argosScreenshot waits for fonts, images and loaders, and stops animations, before it captures the page.

5. Run the tests when the preview is ready

Vercel sends a repository_dispatch event to GitHub when a deployment succeeds, with its URL and the commit it deployed (Vercel docs). Trigger the workflow on it:

# .github/workflows/visual-tests.yml
name: Visual tests

on:
  repository_dispatch:
    types:
      - "vercel.deployment.success"

permissions:
  contents: read
  # Lets Argos find the pull request of the commit.
  pull-requests: read

jobs:
  visual-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          # Test the commit Vercel deployed, not the default branch.
          ref: ${{ github.event.client_payload.git.sha }}

      - uses: actions/setup-node@v6
        with:
          node-version: 22

      - name: Install dependencies
        run: npm ci && npx playwright install --with-deps

      - name: Run Playwright tests
        run: npx playwright test
        env:
          BASE_URL: ${{ github.event.client_payload.url }}
          ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # Only if your previews use Deployment Protection.
          VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}

A few things to know about this event:

  • It runs from your default branch. GitHub starts repository_dispatch workflows only when the file is on your default branch, so merge it before you expect a run. The ref input then checks out the commit Vercel deployed, so the tests come from the same commit as the preview.
  • Argos reads the commit and branch from the event. The Argos SDK takes them from the payload, and finds the pull request with GITHUB_TOKEN. Without it, the build is linked to its branch but not to the pull request.
  • Production deployments run it too. Their builds run on your production branch. Argos approves builds of main automatically by default, so each production deployment refreshes the baseline your previews are compared with.

This guide used the deployment_status event before. Vercel now encourages workflows that depend on it to move to repository_dispatch.

What you get on the pull request

Argos posts an argos commit status on the pull request, failing while changes wait for review, and the build page shows each change next to its baseline.

Argos also detects the preview. Once the build is complete, it reads the URL of the page each screenshot captured, and records the origin most of them share, such as https://my-app-git-feature-login-acme.vercel.app/, as the deployment of that commit. The preview then shows:

  • On the build page, with its URL.
  • On each screenshot. It opens on the same page of the preview: Argos keeps the path and query your test captured and swaps the origin.
  • In the pull request comment, next to the build.
  • In the Deployments tab of your Argos project.

There is nothing to configure. A test that leaves your app for a sign-in or payment page doesn't prevent it. If your tests run on a local server instead, report the preview from CI with argos deploy --url <url>. See Link a deployment hosted elsewhere.

For the same setup with Netlify or Cloudflare, or triggered by deployment_status, see Run on preview deployments.

Supercharge your product quality

See every change your team and your agents make. Review with confidence, and merge faster.