Playwright CI/CD
CI/CD runs Playwright headlessly on every push. Success requires browser install, app startup, env vars, artifact upload, and sensible parallelism.
CI Pipeline Steps
Typical flow: checkout → install deps → npx playwright install --with-deps → build app → npx playwright test → upload report/trace on failure.
Use forbidOnly: !!process.env.CI and retries in config. Never commit test.only.
steps:
- run: npm ci
- run: npx playwright install --with-deps
- run: npm run build
- run: npx playwright test
env:
CI: true
webServer in config can replace manual start server step.
CI Checklist
✓ install browsers + deps
✓ set BASE_URL / secrets
✓ cache node_modules + ~/.cache/ms-playwright
✓ upload html-report + traces on fail
✓ shard or matrix for speed
- Linux CI needs
--with-deps for system libraries. - Cache Playwright browsers between runs.
- Set CI=true for config conditionals.
- Fail build on test failure — don't ignore exit code.
CI/CD Reference
Essential CI practices.
| Practice | Why |
| install --with-deps | Linux browser dependencies |
| Cache browsers | Faster pipeline |
| webServer config | Auto-start app |
| retries on CI | Absorb transient flakes |
| Artifact upload | Debug without local repro |
| merge-reports | Unified report from shards |
Exit Codes and Gates
Playwright exits non-zero on failure — wire directly to pipeline gate. Use --pass-with-no-tests only in optional jobs, not main quality gate.
forbidOnly in CI
forbidOnly: !!process.env.CI fails the build if someone commits test.only — prevents accidental single-test pipelines.
Common Mistakes
- Skipping playwright install in CI.
- Tests hitting localhost without starting server.
- No artifact upload — can't debug CI-only failures.
- Ignoring flaky pass-on-retry without investigation.
Key Takeaways
- CI pipeline: deps, browsers, build, test, artifacts.
- Cache and sharding reduce pipeline time.
- Config adapts to CI via process.env.CI.
- Reports and traces are mandatory for async teams.
Pro Tip
Run the exact CI container image locally with Docker to reproduce 'passes local, fails CI' without pushing commits.