Continuous Integration
Introduction
Playwright tests can be executed in CI environments. We have created sample configurations for common CI providers.
3 steps to get your tests running on CI:
-
Ensure CI agent can run browsers: Use our Docker image in Linux agents or install your dependencies using the CLI.
-
Install Playwright:
# Install NPM packagesnpm ci# Install Playwright browsers and dependenciesnpx playwright install --with-deps -
Run your tests:
npx playwright test
Workers
We recommend setting workers to "1" in CI environments to prioritize stability and reproducibility. Running tests sequentially ensures each test gets the full system resources, avoiding potential conflicts. However, if you have a powerful self-hosted CI system, you may enable parallel tests. For wider parallelization, consider sharding - distributing tests across multiple CI jobs.
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
// Opt out of parallel tests on CI.
workers: process.env.CI ? 1 : undefined,
});
Global timeout
Always set a global timeout in CI. By default a test run has no upper bound, so a suite that hangs, or that slowly grows past the job limit of your CI provider, is killed by the runner mid-run and does not produce the test report.
With testConfig.globalTimeout set, Playwright stops the run itself.
import { defineConfig } from '@playwright/test';
export default defineConfig({
// Fail the run after an hour, so that the reporters still produce a report.
globalTimeout: 60 * 60 * 1000,
});
The examples below therefore do not set a job-level timeout such as timeout-minutes in GitHub Actions. If you do add one, keep it comfortably above globalTimeout, so that Playwright always stops first.
CI configurations
The Command line tools can be used to install all operating system dependencies in CI.
GitHub Actions
On push/pull_request
Tests will run on push or pull request on branches main/master. The workflow will install all dependencies, install Playwright and then run the tests. It will also create the HTML report.
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request: