Playwright sharding divides a test suite across separate Playwright processes. In CI, each process normally runs in its own job or machine, which allows several parts of the suite to execute at the same time.
Sharding can reduce feedback time when one CI job has become the limiting factor. The result depends on test independence, shard balance, available infrastructure, and the setup work repeated by each job.
This article explains how Playwright test sharding works, how it differs from workers and projects, and how to configure sharded execution with merged reports.
Understanding PlayWright Test Sharding
Test sharding divides a test suite into a set of independent subsets called shards. Each shard receives a portion of the test files and runs them in isolation, without coordinating with or depending on other shards.
The goal is to reduce wall-clock execution time by running all shards concurrently on separate machines or pipeline agents.
Sharding differs from intra-process parallelism. Playwright’s –workers flag runs multiple test files in parallel within a single process on a single machine.
Sharding distributes files across separate processes that can run on separate machines entirely. Both mechanisms can be combined: each shard can use multiple workers internally.
Sharding is well-suited for the following situations.
- Large Suite on a Single Agent: When a test suite exceeds what one machine can run in an acceptable time window, distributing it across multiple agents reduces elapsed time proportionally.
- Flat CI/CD Parallelism: Pipeline platforms like GitHub Actions, GitLab CI, and CircleCI support matrix jobs that spin up identical agents simultaneously. Sharding maps directly to this model.
- Cross-Browser Coverage. Running the same suite against Chromium, Firefox, and WebKit in separate shards avoids sequential browser runs.
The tradeoff is coordination overhead. Each shard produces its own test results, and those results must be merged before a final pass/fail decision. Playwright provides tooling for this, covered in the reporting section below.
Playwright Test Sharding: How It Works
Playwright distributes tests across shards by splitting the list of collected test files. The runner collects all test files, sorts them, divides the list into N equal partitions, and assigns partition X to the current shard. Workers within that shard then run only those files.
The mechanism has four components.
1. File-Level Distribution
Playwright shards at the test file level, not at the individual test level. A file always runs on the same shard. This means shard balance depends on file count and individual file duration. A shard containing one file with 200 tests runs longer than a shard containing twenty files with ten tests each, even if the total test count is similar.
2. Deterministic Assignment
The shard assignment is deterministic: the same file always maps to the same shard index for a given N. This makes shard results reproducible and simplifies debugging.
3. Independent Execution
Shards share no state. There is no shared database, no shared browser session, and no coordination between shard processes. Tests that share state through external systems (databases, APIs, file systems) can still conflict, but that is a test design problem, not a sharding problem.
4. Separate Result Artifacts
Each shard produces its own result output. Aggregating those results requires an explicit merge step, described in the reporting section.
Configuring Test Sharding in Playwright
Test sharding in Playwright splits a test suite into smaller shards that run in parallel across multiple workers. The built-in test runner supports this directly, without extra configuration or plugins.
1. Installing Playwright
If Playwright is not yet installed, add it to your project with the following command.
npm install -D @playwright/test
2. Running a Shard from the CLI
The –shard flag takes the form index/total. To split a suite across four shards and run the first one:
npx playwright test --shard=¼
Each agent in a parallel pipeline runs the same command with a different index.
# Agent 1 npx playwright test --shard=1/4 # Agent 2 npx playwright test --shard=2/4 # Agent 3 npx playwright test --shard=3/4 # Agent 4 npx playwright test --shard=4/4
The shard index is one-based. An index of 0 or an index greater than the total will produce an error.
Output –
3. Controlling Workers Within a Shard
Each shard can use multiple workers internally. Set the worker count with the –workers flag.
npx playwright test --shard=1/4 --workers=4
This runs shard 1 of 4 with four parallel workers inside that shard. On a four-core machine, this saturates available CPU. Adjust the worker count to match the available cores on each agent.
4. Configuring Sharding in playwright.config.ts
Worker count and project configuration can be set in playwright.config.ts. The shard index itself cannot be set in the config file because it varies per agent; pass it via the CLI.
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
workers: 4,
projects: [
{
name: 'chromium',
use: { browserName: 'chromium' },
},
{
name: 'firefox',
use: { browserName: 'firefox' },
},
{
name: 'webkit',
use: { browserName: 'webkit' },
},
],
});Output –
When projects are defined, each project’s tests are included in the file list before sharding. A suite with 60 test files across three browser projects produces 180 effective file-project combinations, and those are what get divided across shards.
5. Filtering Tests Before Sharding
The –grep flag filters by test title pattern and applies before shard distribution. Use it to restrict sharding to a subset of tests.
npx playwright test --shard=1/2 --grep="@smoke"
Output –
Only tests tagged @smoke are collected and distributed across the two shards.
Aggregating Results Across Shards
Running shards separately produces separate result artifacts. Without merging them, you get N individual reports with no unified pass/fail summary.
Playwright’s blob reporter and merge-report command address this.
Step 1: Use the Blob Reporter on Each Shard
Configure the blob reporter in playwright.config.ts.
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [['blob', { outputDir: 'blob-report' }]],
workers: 4,
});Output –
Each shard writes its results to a blob-report directory as a binary blob file.
Step 2: Collect Blob Files from All Shards
In a CI/CD pipeline, each shard agent uploads its blob-report directory as an artifact. After all shards complete, a merge job downloads all blob artifacts and places them in a common directory.
Step 3: Merge and Generate the Final Report
Run merge-report against the directory containing all blob files.
npx playwright merge-report --reporter=html ./all-blob-reports
This produces a single HTML report covering all shards. The merge-report command also accepts json and junit reporters, which is useful when a CI/CD system needs a machine-readable result.
Output –
How to Optimize Playwright Test Sharding?’
The default sharding mechanism divides files evenly by count, not by duration. This produces uneven shard runtimes when file durations vary. One shard with a few long-running files becomes the bottleneck regardless of how many shards run in parallel.
The following practices reduce this problem.
1. Profile Shard Duration Before Tuning
Run each shard individually and measure wall-clock time. If shard runtimes are within 10–15% of each other, distribution is acceptable. If one shard takes three times longer than others, rebalancing is needed.
2. Separate Long-Running Tests Into Dedicated Files
Playwright shards at the file level. Moving long-running tests into their own files allows those files to land on their own shards, balancing duration more evenly.
3. Use Tags to Restrict Sharding Scope
If a suite contains both fast unit-like tests and slow integration tests, run them in separate shard groups using –grep to filter by tag. This avoids mixing tests with very different durations in the same shard pool.
4. Set Workers Per Agent Based on Available Cores
Over-subscribing workers on a constrained agent causes resource contention and increases per-test duration. Start with one worker per core and reduce if memory pressure causes failures.
5. Avoid Shared External State
Tests that read from or write to a shared database, shared cache, or shared file path conflict in parallel. Each shard should set up and tear down its own isolated state.
6. Use Playwright’s Retry Mechanism Selectively
The retries config option re-runs failing tests within the same shard. Set it to 1 or 2 for tests known to be intermittently flaky, but do not use retries as a substitute for fixing root causes.
Read More: How to uninstall Playwright
Use Cases and Benefits of Playwright Test Sharding
Sharding is worth the configuration overhead in specific scenarios. The following cases show where it produces measurable benefit.
1. CI Pipeline Time Reduction
A suite that runs in 40 minutes on a single agent can run in 10 minutes across four shards if tests are well-distributed. The reduction is roughly proportional to the number of shards up to the point where shard setup overhead and infrastructure latency become significant.
2. Cross-Browser Test Coverage
Running Chromium, Firefox, and WebKit sequentially triples suite duration. Assigning each browser project to a separate shard runs them concurrently, keeping total pipeline time close to a single-browser run.
3. Regression Suite Isolation
Teams that run a full regression suite only on release branches can shard that suite to keep it within a time window that fits the release process without compromising coverage.
4. Data-Driven Tests With Large Input Sets
Parameterized tests that run across large data sets can be split by grouping data variants into separate test files. Each file then lands on a different shard and runs in parallel.
Read More: Playwright with .Net: A 2026 guide
CI/CD Matrix Sharding
The most common deployment of Playwright sharding uses a pipeline matrix to spin up one job per shard, each running the same command with a different shard index.
The following example uses GitHub Actions.
name: Playwright Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run shard
run: npx playwright test --shard=${{ matrix.shard }}/4
- name: Upload blob report
uses: actions/upload-artifact@v4
if: always()
with:
name: blob-report-${{ matrix.shard }}
path: blob-report/
merge-reports:
needs: test
runs-on: ubuntu-latest
if: always()
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Download all blob reports
uses: actions/download-artifact@v4
with:
path: all-blob-reports
pattern: blob-report-*
merge-multiple: true
- name: Merge reports
run: npx playwright merge-report --reporter=html ./all-blob-reports
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report
path: playwright-report/Output –
The matrix creates four parallel jobs. Each uploads a blob artifact. The merge-reports job waits for all shards, downloads all blobs, and generates a single HTML report. Increasing or decreasing the shard count requires only changing the matrix array and the denominator in –shard.
For GitLab CI, the equivalent pattern uses parallel: 4 and CI_NODE_INDEX and CI_NODE_TOTAL environment variables to construct the shard flag.
test: image: mcr.microsoft.com/playwright:v1.49.0-noble parallel: 4 script: - npm ci - npx playwright test --shard=CINODEINDEX/CI_NODE_TOTAL artifacts: paths: - blob-report/
Output –
Common Challenges in Test Sharding
Sharding introduces coordination and distribution problems that do not exist in single-agent runs.
1. Uneven Shard Duration
When test files vary widely in execution time, one shard consistently takes longer than others, limiting the time savings. Profiling shard runtimes and reorganizing long-running tests into separate files addresses this.
2. Shared External Dependencies
Tests that interact with a shared database, API, or file system can interfere with each other across shards. Tests must either use isolated data fixtures or scope their state to a unique identifier that prevents cross-shard conflict.
3. Flaky Tests Surface More Frequently
Parallel execution increases timing sensitivity. Tests with hidden dependencies on execution order or on timing assumptions that hold in sequential runs will fail intermittently in parallel. Sharding accelerates the discovery of these problems but does not cause them.
4. Report Aggregation Adds Pipeline Steps
Merging shard results requires artifact upload, download, and a merge job. For small suites, this overhead may exceed the time savings from sharding. The blob reporter and merge-report workflow described above keep this overhead low, but it still requires pipeline configuration.
5. Browser Installation Per Agent
Each shard agent must install Playwright browsers independently unless a pre-built image with browsers included is used. npx playwright install –with-deps adds 1–3 minutes to each agent’s startup time. Using a Docker image like mcr.microsoft.com/playwright with browsers pre-installed eliminates this overhead.
6. Debugging Distributed Failures
A failure that occurs on shard 3 of 4 is harder to reproduce locally because the shard assignment is deterministic but not immediately obvious. To reproduce a specific shard’s run locally, use the exact –shard=3/4 flag with the same seed and filter conditions used in the pipeline.
Conclusion
Playwright test sharding distributes a selected test run across independent processes. A reliable setup uses the same inputs for every shard, balances work at the right granularity, keeps tests isolated, limits total concurrency, and merges blob reports after all jobs complete.






