Continuous Integration & Docker
Relevant source files
The following files were used as context for generating this wiki page:
Playwright is designed with robust support for Continuous Integration (CI) environments. This includes features for optimizing test runs, collecting rich metadata, generating aggregated reports from distributed test runs, and providing official Docker images for consistent testing environments. These capabilities ensure that tests are reliable, efficient, and provide actionable feedback within CI/CD pipelines.
This document outlines the key features and configurations related to Playwright's CI and Docker integration, covering metadata capture, sharded test reporting, Docker image management, and strategies for optimizing test execution in a CI pipeline.
CI Metadata Collection
Playwright can automatically capture and embed Git and CI-specific metadata into test reports. This enriches the reports with contextual information about the commit, pull request, and CI build, which is particularly useful for debugging and historical analysis.
Git Commit Information
The playwright:git-commit-info plugin is responsible for collecting Git metadata. It is enabled by default in CI environments or can be explicitly configured.
Sources: packages/playwright/src/plugins/gitCommitInfoPlugin.ts:18-20
Configuration
The captureGitInfo option in playwright.config.ts controls this feature.
| Option | Type | Description | Default |
|---|---|---|---|
commit | boolean | When true, captures commit and pull request information such as hash, author, and timestamp. | true in CI |
diff | boolean | When true, captures the commit diff. This can be used by reporters to provide more intelligent feedback. | true in CI |
Sources: packages/playwright/types/test.d.ts:1143-1163
Data Capture Flow
The plugin gathers information from environment variables for various CI providers and by executing git commands.
This diagram shows the process of collecting Git and CI metadata during a test run.
Sources: packages/playwright/src/plugins/gitCommitInfoPlugin.ts:38-56
Supported CI Providers
The plugin has explicit support for detecting and extracting metadata from the following CI systems:
- GitHub Actions
- GitLab CI
- Jenkins
Sources: packages/playwright/src/plugins/gitCommitInfoPlugin.ts:58-91
The collected information is then available in reporters, such as the HTML report, which displays commit details and links to the CI build.
Sources: tests/playwright-test/reporter-html.spec.ts:805-853
Distributed Test Reporting with Blob Reporter
In CI environments, tests are often parallelized across multiple machines (shards) to reduce execution time. Playwright's blob reporter is designed specifically for this scenario. Each shard generates a .zip file containing its test results, which can later be merged into a single, comprehensive report.
Sources: packages/playwright/types/test.d.ts:16-17, tests/playwright-test/reporter-blob.spec.ts:117-147
Sharding and Merging Workflow
The typical workflow involves running tests with the --shard flag and the blob reporter, then using the playwright merge-reports command to combine the outputs.
This diagram illustrates how test results from multiple shards are collected as blob reports and then merged into a final report.
Sources: tests/playwright-test/reporter-blob.spec.ts:117-147, tests/playwright-test/reporter-blob.spec.ts:476-506
Blob Reporter Configuration
The blob reporter can be configured in playwright.config.ts.
| Option | Type | Environment Variable | Description |
|---|---|---|---|
outputDir | string | PLAYWRIGHT_BLOB_OUTPUT_DIR | Specifies the directory to save blob reports. Defaults to blob-report. |
fileName | string | PLAYWRIGHT_BLOB_OUTPUT_NAME | A specific name for the output zip file. Can include project filters for uniqueness. |
outputFile | string | PLAYWRIGHT_BLOB_OUTPUT_FILE | A full path for the output zip file, overriding outputDir and fileName. |
Sources: packages/playwright/types/test.d.ts:16, tests/playwright-test/reporter-blob.spec.ts:1024-1067
The merging process preserves all test artifacts, including attachments, stdout/stderr, and steps, ensuring the final report is as detailed as a single-machine run.
Sources: tests/playwright-test/reporter-blob.spec.ts:508-543, tests/playwright-test/reporter-blob.spec.ts:894-921
Docker Integration
Playwright provides official Docker images to ensure a consistent and reliable testing environment, especially in CI. These images come with all necessary browser dependencies pre-installed.
Image Build and Publication
The process of building and publishing Docker images is managed by shell scripts within the repository.
Build Flavors and Architectures
Playwright maintains Docker images for multiple Ubuntu versions and CPU architectures:
- Flavors (Ubuntu versions):
jammy(Ubuntu 22.04)noble(Ubuntu 24.04)
- Architectures:
amd64arm64
Sources: utils/docker/publish_docker.sh:18-26
Publishing Workflow
The publish_docker.sh script orchestrates the entire process, from building architecture-specific images to publishing a multi-arch manifest.
This diagram outlines the workflow for building and publishing multi-architecture Docker images for different Ubuntu flavors.
Sources: utils/docker/publish_docker.sh:60-104
The script uses docker manifest to create a single image tag (e.g., v1.56.0-jammy) that points to the appropriate architecture-specific image. This allows users to pull the correct image for their system automatically.
Sources: utils/docker/publish_docker.sh:86-97
Optimizing CI Test Runs
Playwright offers several features to make CI test runs faster and more efficient.
Running Only Changed Files
The --only-changed CLI flag intelligently runs only the tests affected by local Git changes. This is ideal for pre-submit checks on feature branches.
- It detects untracked, modified, and staged files.
- It analyzes the dependency graph to run tests that import changed source files, including component test dependencies.
- It can be combined with a base commit reference (e.g.,
--only-changed HEAD~1) to diff against a specific point in history. - This feature is not compatible with
--watchor--uimodes.
Sources: tests/playwright-test/only-changed.spec.ts:33-138, tests/playwright-test/only-changed.spec.ts:182-186
Project Dependencies for Setup/Teardown
For complex scenarios requiring setup and teardown logic (e.g., seeding a database), Playwright supports dependencies and teardown projects in the configuration. This ensures that setup tasks are executed before dependent test projects and that teardown tasks run after. This pattern is fully supported in CI and works with features like --only-changed.
Sources: packages/playwright/types/test.d.ts:113-142, tests/playwright-test/only-changed.spec.ts:199-228
CDN for Browser Downloads
In CI, Playwright browsers are downloaded from a CDN. The installation process is resilient, with built-in failover mechanisms and connection timeouts to handle network issues gracefully. The primary CDNs are cdn.playwright.dev and playwright.download.prss.microsoft.com.
Sources: tests/installation/playwright-cdn.spec.ts:17-22, tests/installation/playwright-cdn.spec.ts:36-44
Conclusion
Playwright's CI and Docker features provide a comprehensive toolkit for modern development workflows. By integrating Git metadata, offering robust reporting for distributed systems, and supplying pre-configured Docker images, Playwright streamlines the process of running tests in CI. Features like --only-changed and project dependencies further optimize these pipelines, saving time and computational resources.