CI Best Practices in Playwright



Playwright Training
Playwright Training

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.

  1. 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

 

  1. 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

 

  1. 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.

  1. Configure Workers for CI

Limit parallelism to improve stability on shared CI runners.

workers: process.env.CI ? 1 : undefined

Why?

  1. Reduces resource contention
  2. Improves reliability
  3. Prevents flaky tests on low-powered runners

 

  1. Enable Retries Only in CI

Retries help reduce failures caused by temporary network or infrastructure issues.

retries: process.env.CI ? 2 : 0

  1. 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

 

  1. Capture Screenshots on Failure

use: {

screenshot: ‘only-on-failure’

}

This avoids storing unnecessary images while preserving evidence for failed tests.

 

  1. Record Videos on Failure

use: {

video: ‘retain-on-failure’

}

Useful for understanding intermittent UI issues.

 

  1. 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.

  1. Upload Test Artifacts

Archive:

  • HTML Report
  • Trace files
  • Screenshots
  • Videos
  • Logs
Techtutotialz Training, Job support, Interview support
Techtutotialz Training, Job support, Interview support
Tags:
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!