Test against a local dev server
home.test.yaml
Test a preview deployment
Get the preview URL in CI (github.event.pull_request context exposes it
through the vercel deployment status, or use the Vercel CLI 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
silently do nothing for tests that set url:.
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.- Middleware redirects on preview. Auth middleware that redirects (302) to login runs before the bypass cookie is set on the first request: include the bypass params on the initial URL, not only in headers.
- 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 or usepull_request_targetcarefully.