Question

Playwright tests pass locally but every test times out in GitHub Actions

Solved · 411 viewsasked by harriet_g

Claude Code set up Playwright plus a GitHub Actions workflow. Locally all 14 tests pass in about 40 seconds. In Actions every single one fails:

The webServer part of the config:

webServer: {
  command: "npm run dev",
  url: "http://localhost:3000",
  reuseExistingServer: !process.env.CI,
},
What I’ve tried

Raised the timeout to 60 s (still fails, just slower), added npx playwright install to the workflow, re-ran the job three times.

Comment
Do you see any server output in the Actions log before the timeouts? dev_ana

3 answers

Marked as helpful by the asker
katja_s

Two usual suspects, check both:

1. next dev compiles every route on first request. On a small CI runner the first page.goto to each route can take longer than your whole test. Test against a production build in CI:

webServer: {
  command: process.env.CI ? "npm run build && npm run start" : "npm run dev",
  url: "http://localhost:3000",
  reuseExistingServer: !process.env.CI,
  timeout: 180_000,
  stdout: "pipe",
},

2. The app can't start at all in CI. Your .env.local isn't in the repo, so the Supabase/Stripe env vars are missing and the server throws on boot. stdout: "pipe" makes the server log show up in the Actions output, look there first. Add the vars as repository secrets and map them in the workflow's env:.

Comment
It was number 2! NEXT_PUBLIC_SUPABASE_URL missing, crash on startup, and Playwright just waited. Added secrets + build/start, all 14 green in CI. harriet_g
Nice. Keep the build/start anyway, it also catches build errors before Vercel does. katja_s
dev_ana

Also use npx playwright install --with-deps chromium in CI. Without --with-deps the browser can't launch on a clean Ubuntu runner, and with only chromium the step takes seconds instead of minutes.

Comment
arjun_codes

Also upload the report as an artifact (actions/upload-artifact with playwright-report/) and set trace: "on-first-retry". The next time something fails only in CI you can open the trace and see exactly what the page looked like.

Comment
Added it, the trace viewer is amazing. harriet_g