Skip to main content

Overview

Playwright tests integrate seamlessly with CI/CD pipelines. This guide covers best practices for running tests in continuous integration environments across popular platforms.

GitHub Actions

Basic Configuration

Create .github/workflows/playwright.yml:

Matrix Strategy

Test across multiple browsers and Node.js versions:

Sharding Tests

Run tests in parallel across multiple machines:

GitLab CI

Basic Configuration

Create .gitlab-ci.yml:

Multiple Browsers

Jenkins

Jenkinsfile Configuration

CircleCI

Configuration

Create .circleci/config.yml:

Docker

Using Playwright Docker Image

Build and run:

Docker Compose

docker-compose.yml
Run tests:

Best Practices

Optimize CI Configuration

1

Cache dependencies

2

Cache Playwright browsers

3

Use fail-fast: false

4

Set appropriate timeouts

CI-Specific Configuration

Create playwright.ci.config.ts:
Run in CI:

Environment Variables

Set Secrets

Use in Tests

Reporting

HTML Report

Automatically generated after test runs:

JUnit Report

For CI integration:

Slack Notifications

Real-World Example from Playwright Repo

From .github/workflows/tests_primary.yml:

Troubleshooting

Always install browsers with --with-deps flag in CI to ensure all system dependencies are installed.

Tests timing out in CI

Increase timeout in configuration:

Browser installation fails

Use the official Playwright Docker image:

Flaky tests in CI

Enable retries:
Use Playwright Docker images: Official images include all dependencies and are optimized for CI environments.

Performance Tips

  • Use sharding: Split tests across multiple machines for faster execution
  • Cache dependencies: Cache npm packages and Playwright browsers
  • Run tests in parallel: Use multiple workers
  • Use headed: false: Headless mode is faster
  • Minimize retries: Only retry flaky tests in CI
  • Upload artifacts conditionally: Only on failure to save storage
CI runs typically take longer than local runs. Optimize for reliability over speed.