Test against a local dev server
home.test.yaml
Test a preview deployment
Get the preview URL in CI. Thewait-for-vercel-preview action in the workflow
below resolves it, or use the Vercel CLI’s vercel inspect.
URL resolution is ordered: --url-override overrides a test’s url: field,
which takes precedence over the environment’s baseUrl. The sample test pins
url: for local runs, so point the run at the preview explicitly:
url: fall through to the environment, so you can instead
keep url off the test and select environments[].baseUrl with
--env preview. Use one convention per repo. Mixed pinning makes --env a base
URL ineffective for tests that set url:. The environment still supplies its
variables and browser settings.
Bypass deployment protection
Vercel’s standard protection blocks unauthenticated requests, including test browsers. Two options, both covered in Test Vercel protected preview environments:- Send
x-vercel-protection-bypass+x-vercel-set-bypass-cookieheaders on every request (fast; can hit CORS limits). - Append
?x-vercel-protection-bypass=<secret>&x-vercel-set-bypass-cookie=trueto the base URL (works through CORS; Vercel converts it to a cookie).
VERCEL_AUTOMATION_BYPASS_SECRET, and pass it through envVariables or the
shell environment. Never commit it.
In CI
A complete GitHub Actions job that waits for the preview, then runs the suite with the bypass header:.github/workflows/preview-tests.yml
--custom-headers adds the bypass to every request the test makes. If your app
sends cross-origin fetches that reject the header, switch to the query-param
form from Option B instead.
Next.js pitfalls
- Hydration timing.
next devand React transitions can leave elements visible-but-inert briefly. Assert on the post-hydration state (“the Sign in button is clickable”) rather than adding fixed waits. next/imageand visual assertions. Placeholder blur and lazy images make pixel-level checks racy; keep visual assertions on stable regions.- Vercel’s deployment-protection bypass does not sign in to your app. Include the app’s login or session setup even when the deployment accepts the bypass header or query parameters.
- Preview vs production data. Point
NEXT_PUBLIC_*env vars at staging backends for previews so tests exercise realistic data without touching production. VERCEL_AUTOMATION_BYPASS_SECRETin forks. GitHub does not pass secrets to workflows from forks; gate the test job withif:on same-repo PRs. Do not switch topull_request_target: it runs with your repo’s secrets while checking out fork-controlled code, which exposes those secrets.