- Jul 14, 2026
- admin
- 0

Playwright CI/CD Best Practices: Build Reliable and Scalable Test Pipelines
CI (Continuous Integration) is not just about running Playwright tests after every commit—it’s about making your test execution fast, reliable, maintainable, and production-ready. Here are the most important CI best practices for Playwright that you can include in your tutorial or use in your projects.
- Use npm ci Instead of npm install
npm ci installs dependencies exactly as specified in package-lock.json, making builds reproducible and faster.
– run: npm ci
Why?
- Faster installation
- Consistent dependency versions
- Ideal for CI environments
- Install Playwright Browsers
Always install the required browsers in the pipeline.
– run: npx playwright install –with-deps
Benefits
- Installs browser binaries
- Installs required Linux dependencies
- Avoids “Executable doesn’t exist” errors
- Run Tests in Headless Mode
Headed mode requires a display server and slows down execution.
use: {
headless: true
}
Headless mode is recommended for CI pipelines.
- Configure Workers for CI
Limit parallelism to improve stability on shared CI runners.
workers: process.env.CI ? 1 : undefined
Why?
- Reduces resource contention
- Improves reliability
- Prevents flaky tests on low-powered runners
- Enable Retries Only in CI
Retries help reduce failures caused by temporary network or infrastructure issues.
retries: process.env.CI ? 2 : 0
- Collect Traces on Failure
Traces make debugging much easier.
use: {
trace: ‘on-first-retry’
}
A trace includes:
- Screenshots
- Network activity
- DOM snapshots
- Console logs
- Timeline
- Capture Screenshots on Failure
use: {
screenshot: ‘only-on-failure’
}
This avoids storing unnecessary images while preserving evidence for failed tests.
- Record Videos on Failure
use: {
video: ‘retain-on-failure’
}
Useful for understanding intermittent UI issues.
- Publish HTML Reports
Generate and publish Playwright reports as CI artifacts.
npx playwright show-report
Store reports so they can be downloaded after pipeline completion.
- Upload Test Artifacts
Archive:
- HTML Report
- Trace files
- Screenshots
- Videos
- Logs

