TL;DR
This article explains test orchestration on a Playwright pipeline. The fixes run from splitting spec files and fullyParallel up to duration-based orchestration.
Test orchestration coordinates the tests in a suite into one workflow with one pass/fail result. It decides which tests run where, in what order, and what the combined result is. On Playwright, start with fullyParallel, small spec files and merged blob reports, and move to duration-based balancing only once the slowest shard stays well behind the rest after those fixes.
- Measure seconds per shard from real CI runs, not tests per shard.
- Break the slowest spec files along feature lines and turn on
fullyParallel: true. - Run one job per shard from a GitHub Actions matrix, and merge the shards' blob reports with
npx playwright merge-reports.
Once a Playwright suite runs long enough that people stop waiting for it, someone splits it into shards and adds machines. When test files are unevenly sized, some shards may end up running significantly more tests than others. Playwright's sharding docs describe the even case: split into four shards, each running one fourth of the tests, and run in parallel on different jobs, the suite completes four times faster.
To shard the suite, pass --shard=x/y to the command line; each run executes only the selected shard. By default, Playwright hands whole test files to shards. When files are unevenly sized, some shards may run far more tests than others, and some may run fewer or none. Without fullyParallel, a whole spec file goes to one shard, and the tests in a single file run in order, in the same worker process.
Playwright splits the suite with --shard=x/y, and npx playwright merge-reports merges the shards' blob reports into a single report. With fullyParallel: true, each shard attempts to balance the number of individual tests it runs. So the fix starts with measuring that gap in seconds, from your own runs.
What test orchestration means
Test orchestration sounds abstract until you map it onto a pipeline you already run. Orchestration coordinates the tests in a suite into one workflow with one pass/fail result, and it does that by making four decisions. On a Playwright pipeline, each decision already has an owner:
- Order decides which tests run together and which wait. By default, Playwright runs test files in parallel, while the tests inside one file run in order in the same worker process.
- Placement decides which machine runs what.
--shard=x/ysplits the suite into shards, and in a CI pipeline each shard can run as a separate job. - Inputs are what each run gets: browsers, base URLs, environment variables. Projects are configured in
playwright.config.ts, and you use them to run tests on different browsers and devices. - Outcome is one verdict for the whole run. If you add the
blobreporter to the config on CI, each shard's blob report can be merged into a single report withnpx playwright merge-reports.
Seen as a loop, every orchestrated run follows the same steps. A trigger starts it, and the tests get selected and ordered. Environments and data get prepared, tests get distributed and run, results get collected and merged, and someone acts on them. On a sharded Playwright pipeline, the distribute step is where the time goes.
Orchestration and its neighbors
Test automation writes and runs individual tests. Orchestration decides where and when those tests run, and gathers what they report. The terms around it each answer a different question:
| Term | The question it answers |
|---|---|
| Test automation | Does this test pass? |
| Parallel testing | How many tests run at once? |
| CI/CD | When does the pipeline run, and what does its result block? |
| Selenium Grid | Where does the browser run? |
| Test orchestration | Which tests run where, in what order, and what is the combined result? |
A pool of remote browsers is not orchestration. Something still has to decide which test goes to which machine, and collect the results afterward.
Don't confuse any of this with Android Test Orchestrator, which shares the name and plays no part in a Playwright pipeline.
How Playwright assigns shards
By default, Playwright shards test files, not individual tests. Playwright can only shard tests that can run in parallel, which by default means it shards test files (sharding docs). Without fullyParallel, whole files go to shards, and a file's tests run in order in one worker.
Without fullyParallel, entire test files are assigned to shards, so an oversized file goes whole to one shard per project, however many shards you add. When file sizes are uneven, some shards may run significantly more tests than others, while others may run fewer or none at all.
Projects multiply the split
Multiple projects, such as one per browser, change the picture. The same file may land in different shards for different projects, so "one shard per file" is the wrong mental model. One user with four browser projects and fully parallel mode off expected each shard to own a file, and found every shard running the same test in a different browser instead (#33911). A maintainer replied in #33911 that this works as intended: each test runs once per project, and the scheduler spreads those runs evenly across shards.
Skipped tests weigh nothing
Statically skipped tests, marked with test.skip() or test.fixme(), don't count when Playwright balances shards, because they never run. A file full of tests marked fixme looks big in the editor and weighs nothing in the split.
Setting the split
The --shard flag runs only the selected shard, written as current/all and counted from 1:
npx playwright test --shard=1/4
npx playwright test --shard=2/4
npx playwright test --shard=3/4
npx playwright test --shard=4/4
The same split can live in the config as shard, in the one-based form { total: 5, current: 2 }:
import { defineConfig } from '@playwright/test';
export default defineConfig({
// One config for every CI job: each job sets its own index
shard: process.env.SHARD_INDEX
? {
current: Number(process.env.SHARD_INDEX),
total: Number(process.env.SHARD_TOTAL),
}
: null,
});
We'd keep the split on the command line, where a CI matrix sets it in plain sight, and use the config form only when a wrapper script owns the npx playwright test call.
Measuring shard imbalance
A balanced pipeline is one where the shards finish together, so measure seconds per shard, not tests per shard. We treat the gap between the fastest and the slowest shard as the time you can win back.
Anti-pattern
Counting tests per shard
You turn on fullyParallel, see that every shard ran about the same number of tests, and call the split balanced. With fullyParallel, each shard does try to balance the number of individual tests it runs. Count is the wrong unit, though. Picture one shard that drew a four-minute checkout test plus twenty two-second tests, next to a shard that drew twenty-one two-second tests. Both ran 21 tests. The first needs close to five minutes, and the second is done in under one.
Fix
Add up durations per file and per shard from real CI runs, and compare shards by their totals. The reporter below does the adding.
Per-file timings
Every test result carries testResult.duration, its running time in milliseconds. A small custom reporter can total those per spec file and print the slowest files for the shard it ran in:
// shard-timing-reporter.ts
import type { FullConfig, Reporter, TestCase, TestResult } from '@playwright/test/reporter';
class ShardTimingReporter implements Reporter {
private shardLabel = 'unsharded';
private fileDurations = new Map<string, number>();
onBegin(config: FullConfig) {
if (config.shard) {
this.shardLabel = `${config.shard.current}/${config.shard.total}`;
}
}
onTestEnd(test: TestCase, result: TestResult) {
const file = test.location.file;
this.fileDurations.set(file, (this.fileDurations.get(file) ?? 0) + result.duration);
}
onEnd() {
const totalMs = [...this.fileDurations.values()].reduce((sum, ms) => sum + ms, 0);
const slowest = [...this.fileDurations.entries()]
.sort((a, b) => b[1] - a[1])
.slice(0, 10);
console.log(`Shard ${this.shardLabel}: ${(totalMs / 1000).toFixed(1)}s of test time`);
for (const [file, ms] of slowest) {
console.log(` ${(ms / 1000).toFixed(1)}s ${file}`);
}
}
}
export default ShardTimingReporter;
Each shard prints its own total, so the logs of one CI run give you the per-shard comparison. The number is summed test time. With more than one worker in a shard, tests run at the same time, so the sum can run higher than the shard's wall-clock time. Compare shards that use the same worker count.
Slow files and idle workers
reportSlowTests treats spec files that take longer than threshold milliseconds as slow, and reports the slowest of them, up to max. Register it next to the timing reporter:
import { defineConfig } from '@playwright/test';
export default defineConfig({
fullyParallel: true,
reporter: [['list'], ['./shard-timing-reporter.ts']],
// Flag spec files that take over a minute, at most 10 of them
reportSlowTests: { max: 10, threshold: 60_000 },
});
The files it lists are where to split first.
To see what happens inside a shard, use the Perfetto reporter. It renders the run as a timeline with one lane per worker, where each test is a slice holding its hooks, fixtures and steps. A lane that goes quiet early is a worker with nothing left to do. Each slice carries the test's source location. By default, the tests in a single file run in order, in the same worker process, so a file that doesn't run in fully parallel mode shows up as a chain of slices in one lane.
Keep the timing reporter on in every CI run, not only when someone complains about the pipeline. Duration-based balancing works from recorded timings too, and reading them every run catches a new slow file soon after it lands.
Splitting specs and fullyParallel
The cheapest fix for an uneven split is changing what Playwright has to split. Without fullyParallel, tests are split at the file level, so balance comes from keeping test files small and evenly sized. Take the top of the slow-file list and break each file along feature lines: a checkout file that covers cart, payment and confirmation becomes three files the split can place separately.
The bigger lever is fullyParallel: true. Playwright's sharding docs recommend it for a balanced distribution across shards, especially in CI, and say that without it you may need to organize test files by hand. With the option on, the whole run executes all tests in all files concurrently. Sharding then works per test, so one file's tests spread across shards.
There is a limit. fullyParallel makes each shard attempt to balance the number of individual tests it runs, so a few slow tests can still leave one shard behind, as the counting example showed.
Anti-pattern
A large serial spec
A big spec file's tests share state: the first test creates an account, the next fills a cart with it, the last pays. To keep them in order, the file goes into serial mode. Playwright keeps a serial group in one worker, and so on one shard. Playwright can only shard tests that can be run in parallel, so a serial file stays on one shard however many machines you add.
// Anti-pattern: serial mode keeps every test in this file, slow ones included, in one worker on one shard
import { test, expect } from '@playwright/test';
test.describe.configure({ mode: 'serial' });
test('creates an account', async ({ page }) => {
await page.goto('https://example.com/signup');
await page.getByLabel('Email').fill('buyer@example.com');
await page.getByRole('button', { name: 'Create account' }).click();
await expect(page.getByText('Welcome')).toBeVisible();
});
test('fills the cart', async ({ page }) => {
await page.goto('https://example.com/products/notebook');
await page.getByRole('button', { name: 'Add to cart' }).click();
await expect(page.getByTestId('cart-count')).toHaveText('1');
});
test('pays and sees the confirmation', async ({ page }) => {
await page.goto('https://example.com/checkout');
await page.getByRole('button', { name: 'Pay now' }).click();
await expect(page.getByText('Order confirmed')).toBeVisible();
});
Fix
Make the tests isolated so each one builds its own state, as Playwright advises instead of serial mode, then let fullyParallel spread them:
import { defineConfig } from '@playwright/test';
export default defineConfig({
// Every test in every file can run concurrently, and shards split per test
fullyParallel: true,
});
Run a large file's independent tests in parallel with test.describe.configure():
// cart.spec.ts
import { test, expect } from '@playwright/test';
// Each test builds its own cart, so the tests can run in parallel
test.describe.configure({ mode: 'parallel' });
test('adds an item to the cart', async ({ page }) => {
await page.goto('https://example.com/products/notebook');
await page.getByRole('button', { name: 'Add to cart' }).click();
await expect(page.getByTestId('cart-count')).toHaveText('1');
});
test('removes an item from the cart', async ({ page }) => {
await page.goto('https://example.com/products/notebook');
await page.getByRole('button', { name: 'Add to cart' }).click();
await page.goto('https://example.com/cart');
await page.getByRole('button', { name: 'Remove' }).click();
await expect(page.getByText('Your cart is empty')).toBeVisible();
});
Because the file sets mode: 'parallel', its tests can run in parallel, and only tests that can run in parallel can be sharded.
Sharding in GitHub Actions
The matrix is where placement stops being a flag and becomes CI config: one job per shard, then one job that turns their output into a single result. GitHub Actions shards tests across jobs with jobs.<job_id>.strategy.matrix, which runs a separate job for every combination of the options you give it. A matrix over shardIndex and shardTotal gives one job per shard, each running --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}.
On CI, each shard writes a blob report instead of HTML, here alongside the timing reporter:
import { defineConfig } from '@playwright/test';
export default defineConfig({
fullyParallel: true,
// Blob reports on CI so the shards can be merged, HTML locally
reporter: process.env.CI
? [['blob'], ['./shard-timing-reporter.ts']]
: [['html']],
});
Each shard uploads its blob report to the GitHub Actions Artifacts. The whole workflow:
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
playwright-tests:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
- name: Upload blob report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: blob-report-${{ matrix.shardIndex }}
path: blob-report
retention-days: 1
merge-reports:
if: ${{ !cancelled() }}
needs: [playwright-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Download blob reports
uses: actions/download-artifact@v4
with:
path: all-blob-reports
pattern: blob-report-*
merge-multiple: true
- name: Merge into one HTML report
run: npx playwright merge-reports --reporter html ./all-blob-reports
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report--attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 14
- name: Fail if any shard failed
if: ${{ needs.playwright-tests.result != 'success' }}
run: exit 1
The merge-reports job depends on the sharded job through needs: [playwright-tests], which fixes the order: shards first, merge after. Blob report names contain the shard number, so all four reports land in one all-blob-reports directory without clashing. npx playwright merge-reports turns them into one HTML report.
The last step fails merge-reports when any shard failed, which makes it the one required check for the run. Require that one job before a pull request can merge, and open its report when a run goes red. Every shard's failures sit in that one report, so you reproduce from it instead of reading four job logs.
CircleCI
CircleCI indexes shards from 0, and --shard counts from 1, so override CircleCI's default parallelism environment variables before you pass them to Playwright.
Anti-pattern
Merging stale blob reports
You run the suite on 4 shards, cut it to 3, and merge from a directory that still holds the last run's zips. The fourth shard's old report gets merged in, and its old results show up next to the new ones. A user reported that the blob reporter had stopped clearing its output directory, so merges picked up stale zips, and a maintainer replied that this is the new intended behavior (#43161). Playwright 1.64 kept reports with other names. Since Playwright 1.65, the blob reporter again deletes the content of its output directory before it writes the report, as the release notes say.
Fix
Delete the blob directory before each run, and merge from a directory the merge job creates fresh, as all-blob-reports is in the workflow above:
rm -rf blob-report all-blob-reports
npx playwright test --shard=1/3
Duration-based orchestration
Every fix so far changes what Playwright has to split, not how it splits. With fullyParallel: true, each shard attempts to balance the number of individual tests it runs; without fullyParallel, entire test files are assigned to shards. Users have reported shards finishing at different times and asked Playwright for load balancing between tests (#20116). The request was closed as not planned. The GitHub Actions matrix doesn't change that either: it starts one job per combination of options, and each job still runs Playwright's split.
Duration-based orchestration lets recorded timings decide placement instead.
Balanced shards
The first shape keeps the matrix and changes the split: each --shard job still runs, but recorded durations decide which tests it gets. Currents Balanced Sharding has each shard fetch the recent durations of your spec files and split the tests so the shards finish at about the same time, while the --shard jobs stay as they are. The split uses the last 7 days of runs from the same project, and until at least one spec file has 3 recorded runs, every shard splits the way Playwright does.
A live queue
The second shape drops fixed shards altogether. CI machines take pending tests from a shared queue as each one frees up, so a machine that finishes early takes the next pending test instead of sitting idle. Currents Test Orchestration assigns no tests to CI machines in advance and hands out tests from a live queue of pending tests as each machine becomes available. The orchestrator records test durations and uses that history to improve the distribution in later runs.
Picking a shape
Pick balanced shards when the matrix is shared config you'd rather not touch. The workflow file stays the same, and only the split changes. Pick the queue when no assignment should be fixed before the run starts, which pays off most when test durations swing from run to run.
Either way, duration balancing still works with the units Playwright gives it. Under balanced sharding, tests that Playwright keeps in one worker stay on one shard: the tests of a file that isn't in fully parallel mode, or a describe.serial group. Do the spec splitting and fullyParallel work first, because a scheduler can only place the pieces you've made small enough to move.
When sharding stops helping
More shards help only when test time is what makes the pipeline slow. Each shard is a separate job, so each one repeats the job's setup: in the workflow above, checkout, dependency install and the browser install run once per shard. On a small suite, that repeated setup can outweigh the test time it splits up, and the pipeline gets slower as you add machines.
The worker count is the other knob. The workers option defaults to half the number of logical CPU cores, while Playwright's CI guide recommends setting it to 1 in CI to prioritize stability and reproducibility. Those two pull in opposite directions, so measure instead of guessing. Run the suite on a bigger runner with more workers over several runs. If failures stay where they were, more workers on one machine beat another round of per-shard setup. The trade-off between more workers and more shards is the same question at a larger scale.
Shards also share whatever they test against. Point four shards at one staging backend and their tests hit the same accounts and the same rows at the same time. Tests that aren't isolated start failing each other, and more shards means more of that contention. A duration split can't fix that. Isolated tests can, and Playwright recommends making tests isolated over running them in serial mode.
Failures like these look like flaky tests, and how you retry and track flaky tests is a separate decision from placement. A scheduler decides where a test runs and has no say in whether its failure is real, so handle retries and flaky-test tracking on their own, outside the shard-balancing question.
Anti-pattern
More shards for a fixed cost
The pipeline is slow, so the matrix goes from 4 shards to 8. If the time goes to per-shard setup, each new shard pays that setup again. If the time goes to one serial file, that file still runs in one worker on one shard. Either way the CI bill grows and the wall-clock time barely moves.
Fix
Read the per-shard timings before you touch the matrix. If setup dominates, use fewer, bigger machines. If one file dominates, split it or isolate its tests. That file sets a floor no scheduler can go below, and the fix lives in the tests.
Choosing an orchestration approach
Start native. Turn on fullyParallel, keep spec files small, and merge blob reports from a GitHub Actions matrix. That setup costs only config, and for plenty of suites it is all the orchestration they need.
Then measure seconds per shard on every run. Once the slowest shard stays well behind the rest after the native fixes, move to duration-based balancing: balanced shards if you want the matrix unchanged, a live queue if you'd rather nothing were fixed before the run.
Match the scope to the pipeline stage. Run the cheap checks first, unit and integration tests before the browser suite, so a broken build fails before every shard has paid its setup. A quick subset of browser tests belongs on pull requests, where fast feedback matters most, and the full sharded suite belongs on nightly runs and the pre-release check. That full run is where balanced shards pay off most, because it has the most seconds to spread.
The tools sort by how much they decide for you. CI platforms such as GitHub Actions and CircleCI start the jobs and hand each one its index. Playwright splits the suite with --shard, and merges the results with merge-reports. Orchestration services decide placement from recorded durations. Pick the lowest layer that closes the gap your timings show, and move up a layer only when the numbers say the one below has run out.
Frequently asked questions
What is test orchestration?
Test orchestration coordinates the tests in a suite into one workflow with one pass/fail result.
How does Playwright split tests across shards?
By default, Playwright shards test files, not individual tests. Without fullyParallel, entire test files are assigned to shards, so an oversized file goes whole to one shard per project, however many shards you add. How Playwright assigns shards covers projects and skipped tests too.
What does fullyParallel do for Playwright sharding?
With fullyParallel: true, sharding works per test, so one file's tests spread across shards.
How do I measure shard imbalance in Playwright?
Measure seconds per shard, not tests per shard, because a balanced pipeline is one where the shards finish together.
Why does merge-reports pick up stale blob reports?
If you merge from a directory that still holds the last run's zips, old reports get merged in. Delete the blob directory before each run, and merge from a directory the merge job creates fresh, as Merging stale blob reports explains.
When does adding more Playwright shards stop helping?
More shards help only when test time is what makes the pipeline slow. Each shard is a separate job, so each one repeats the job's setup.
What is duration-based test orchestration?
Duration-based orchestration lets recorded timings decide placement. With balanced shards, each --shard job still runs, but recorded durations decide which tests it gets. With a live queue, there are no fixed shards: CI machines take pending tests from a shared queue as each one frees up, as Duration-based orchestration describes.




