Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud
AIAutomation TestingCI/CD

Running Automated Tests Against Vercel Preview URLs

The deployment_status trigger, the protection-bypass header, and a real GitHub Actions workflow for E2E testing on every preview.

Author

Mythili Raju

Author

Author

Shahzeb Hoda

Reviewer

Published on: August 27, 2026

Your CI job finds the preview URL, launches Playwright against it, and every test fails on a login screen your app doesn't have. Nothing broke in the deploy. Vercel's own Deployment Protection is doing exactly what it's configured to do: gate the URL from anyone without a session, including your test runner.

That single wrong turn accounts for most "why can't I test my preview deployment" threads. The fix is documented, current, and narrower than most guides make it sound.

This covers how previews actually trigger, the two URL types, getting the URL into CI, the protection bypass for both API and in-browser tests, a working GitHub Actions workflow, and a one-command alternative to maintaining a Playwright spec for every preview.

TL;DR

Testing a Vercel preview deployment automatically means capturing the exact preview URL from the deployment_status GitHub event, then sending the x-vercel-protection-bypass header (or an x-vercel-set-bypass-cookie for a multi-page browser session) so your test traffic clears Deployment Protection the same way a real teammate's session does.

  • The trigger: deployment_status fires on your repo; filter state=success and environment=Preview to get the exact URL.
  • The gate: Deployment Protection blocks unauthenticated traffic by default, including your CI job, unless you bypass it deliberately.
  • The bypass: VERCEL_AUTOMATION_BYPASS_SECRET as a header for API calls, plus a bypass cookie for a real browser session.
  • Verification: TestMu AI's Kane CLI runs a plain-English check against the preview URL with the same header, no spec file to maintain.

How Previews Actually Trigger

Vercel's environments documentation defines three defaults: Local, Preview, and Production. A Preview deployment is created when you push a commit to a non-production branch, open a pull request, or run the CLI without --prod.

One exception worth knowing before it confuses a first CI run: the very first deployment of a brand-new project is always a production deployment, regardless of which branch or flag you used.

The Two Preview URL Types

URL typePoints toUse for automated tests?
Branch-specificAlways the latest deployment on that branchRisky - a new push can swap the app underneath a still-running test
Commit-specificThe exact deployment of that one commit, permanentlyPreferred - ties the test run to the exact code it validated

Grab the commit-specific URL from the deployment event rather than constructing the branch URL yourself; the next section covers exactly where that URL lives.

Getting the URL Into CI

GitHub fires a deployment_status event on your repository as Vercel's integration creates and updates the deployment. Filter it for the moment the deployment finished successfully:

on:
  deployment_status:

jobs:
  e2e:
    if: github.event.deployment_status.state == 'success' &&
        github.event.deployment_status.environment == 'Preview'
    runs-on: ubuntu-latest
    steps:
      - name: Capture the preview URL
        run: echo "PREVIEW_URL=${{ github.event.deployment_status.target_url }}" >> $GITHUB_ENV

That target_url field is the commit-specific preview URL. Everything downstream, Playwright, Kane CLI, or any other tool, points at $PREVIEW_URL from here.

Note

Note: TestMu AI's Kane CLI takes the captured preview URL and a plain-English objective, no Playwright spec required. Try TestMu AI free!

The Protection Bypass Every Guide Gets Half Right

Vercel's Protection Bypass for Automation documentation exists because Deployment Protection, Vercel Authentication, Password Protection, or Trusted IPs, is on by default for most teams and blocks exactly the traffic a test runner sends.

Vercel automatically sets a secret as the VERCEL_AUTOMATION_BYPASS_SECRET system environment variable once bypass is configured for the project. The documented, recommended method is sending it as a header:

  • Header (recommended) - x-vercel-protection-bypass: <secret> on the request, the right choice for most automation.
  • Query parameter - reserved for tools that can't set custom headers, like third-party webhook verification (Slack, Stripe, GitHub).

Here's the part most guides skip: a single header only clears the one request it's attached to. A real browser session, the kind an E2E test drives, makes many requests as it navigates. For that, Vercel's docs specify a second header, x-vercel-set-bypass-cookie: true, which sets the bypass as a cookie via a redirect so every subsequent page load in the session stays authorized. Inside an iframe, the value needs to be samesitenone instead.

Wiring It Into GitHub Actions

Vercel's own documentation ships a Playwright example using exactly these two headers together:

// playwright.config.ts
import { defineConfig } from '@playwright/test';

if (!process.env.VERCEL_AUTOMATION_BYPASS_SECRET) {
  throw new Error(
    'VERCEL_AUTOMATION_BYPASS_SECRET is required to run tests against protected deployments',
  );
}

export default defineConfig({
  use: {
    extraHTTPHeaders: {
      'x-vercel-protection-bypass': process.env.VERCEL_AUTOMATION_BYPASS_SECRET,
      // Use 'samesitenone' instead of 'true' when testing in an iframe.
      'x-vercel-set-bypass-cookie': 'true',
    },
  },
});

Combined with the deployment_status trigger from earlier, the full loop is: capture $PREVIEW_URL, run Playwright with these headers against it, and the run neither times out on a login screen nor accidentally tests the wrong commit.

Verifying With Kane CLI

Writing and maintaining a Playwright spec is the right call for a stable, well-defined flow. For a fast smoke check on every single preview, Kane CLI from TestMu AI skips the spec file: a plain-English objective, run headless with the same bypass header, against the same captured URL.

npm install -g @testmuai/kane-cli
kane-cli login --username "$LT_USERNAME" --access-key "$LT_ACCESS_KEY"

kane-cli run --agent --headless \
  --url "$PREVIEW_URL" \
  --header "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" \
  "sign in with the test account, open the dashboard, assert the page
   shows the account name"

Agent mode's standard exit codes (0 passed, 1 failed, 2 environment error, 3 timeout) drop straight into the same GitHub Actions job as a required check, no separate reporting step. Our dedicated guide to connecting Kane CLI to GitHub Actions covers the full workflow setup, and the Kane CLI introduction documentation covers authentication and the full command reference.

Get Kane CLI certified for free with TestMu AI

Custom Environments for Staging and QA

Beyond the default Preview environment, Vercel's Pro plan allows one custom environment per project, and Enterprise allows twelve, per the current documentation. A custom environment like staging can track a specific branch automatically and hold a persistent domain, unlike the constantly-changing default Preview URLs.

A longer-running QA environment is the right target for a fuller regression pass; the per-commit preview URL from earlier is the right target for a fast smoke check on every single change.

Common Failures and Fixes

  • Every test fails on a login page - Deployment Protection is on and the bypass header is missing or the secret is stale after a project setting change.
  • The first request passes, later navigations fail - the header alone isn't enough for a multi-page session; add x-vercel-set-bypass-cookie.
  • Tests run against the wrong version of the app - the job used a branch URL instead of the commit-specific target_url, and a later push changed what it served mid-run.
  • The workflow never fires - the deployment_status filter checked the wrong environment name; Vercel reports it as exactly "Preview," case-sensitive.

Getting Started

Four steps from zero to a preview check that actually runs.

  • Enable Protection Bypass for Automation on the Vercel project and confirm VERCEL_AUTOMATION_BYPASS_SECRET appears in deployment environment variables.
  • Add the deployment_status trigger to a GitHub Actions workflow and capture target_url as an environment variable.
  • Send both bypass headers, protection-bypass and set-bypass-cookie, from whichever tool runs the check.
  • Start with one smoke objective on the flow that would hurt most if it broke, via Kane CLI or Playwright, before expanding coverage.

Once the loop runs reliably on every preview, our guide to agent-native CI covers the next step: having an agent triage what actually failed, not just report that it did. If the same check is gating an AI-generated pull request specifically, our breakdown of quality gates for AI pull requests covers where this fits in that broader review process.

Author

...

Mythili Raju

Blogs: 51

  • Twitter
  • Linkedin

Mythili is a Community Contributor at TestMu AI with 3+ years of experience in software testing and marketing. She holds certifications in Automation Testing, KaneAI, Selenium, Appium, Playwright, and Cypress. At TestMu AI, she leads go-to-market (GTM) strategies, collaborates on feature launches, and creates SEO optimized content that bridges technical depth with business relevance. A graduate of St. Joseph’s University, Bangalore, Mythili has authored 35+ blogs and learning hubs on AI-driven test automation and quality engineering. Her work focuses on making complex QA topics accessible while aligning content strategy with product and business goals.

Reviewer

...

Shahzeb Hoda

Reviewer

  • Linkedin

Shahzeb Hoda is the Associate Director of Marketing and a Community Contributor at TestMu AI, leading strategic initiatives in developer marketing, content, and community growth. With 10+ years of experience in quality engineering, software testing, automation testing, and e-learning, he has authored and reviewed 70+ technical articles on software testing and automation. Shahzeb holds an M.Tech in Computer Science from BIT, Mesra, and is certified in Selenium, Cypress, Playwright, Appium, and KaneAI. He brings deep expertise in CI/CD pipeline automation, cross-browser testing, AI-driven testing practices, and framework documentation. On LinkedIn, he is followed by 3,700+ engineers, developers, DevOps professionals, tech leaders, and enthusiasts.

Add to Google preferred sources

Summarise with AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

Testing Vercel Preview Deployments FAQs

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests