Playwright Sharding: Balance CI and Merge Reports
Diagnose uneven Playwright shards, compare file and parallel distribution, then merge blob reports without losing a test or a failure.
BotBrowser Team

Want the structured docs for Getting Started?
This article lives in the editorial library. For step-by-step setup, reference material, and ongoing updates, jump into the docs section.
A Playwright sharding run can look finished while one CI job still waits on a single slow file. Every shard exits successfully, then the combined job produces several partial reports and no answer to whether all tests ran. Sharding chooses a subset of tests; a blob report and merge-reports reconstruct one result across those subsets. Neither step makes an unequal duration distribution fair.
BotBrowser can launch its executable and declared profile under Playwright control in an authorized CI fixture, but it does not partition tests, choose a shard count, reschedule a slow file or merge report files. The runner owns those decisions, and the CI service owns whether every artifact reached the merge job.
TL;DR
- Read the per-shard duration and test count before changing
workers. Unequal shard time is an assignment problem first, not a browser-speed claim. --shard=1/2selects tests by the runner's sharding strategy; it does not measure previous durations and rebalance them automatically.- A blob report preserves structured results per shard.
merge-reportsconsumes all blobs and emits one reproducible report. - Keep failed shard artifacts and merge them too; a report that contains only successful shards has erased the test failure.
- One readable merged report proves accounting for the uploaded blobs. It does not prove another CI service uploaded them correctly.
Contents
- Why equal shard counts can finish at different times
- The owned two-shard experiment
- Read the distribution before increasing workers
- Merge reports without losing a test
- Preserve the CI boundary
- Practical conclusion
Why equal shard counts can finish at different times
Playwright has three separate scheduling controls. --shard divides the selected tests among jobs. workers sets the concurrency inside one job. fullyParallel changes whether parallel scheduling can split tests within a file, rather than treating each file as the smallest scheduling unit while parallel workers run. The sharding guide also documents report merging, and the parallel guide describes worker and parallelism scope.
Those controls answer different questions. Shard count asks how many CI jobs receive subsets. Worker count asks how many test workers one job runs at once. fullyParallel asks what unit the scheduler may distribute. Increasing any one changes resource pressure and test assignment; none promises that measured setup, action or teardown cost is equal.
The important word is selected tests. A filter can exclude a slow file from every shard. A test.only can reduce the suite to one case. A shard can receive only fast files while a sibling receives a file whose one test performs a long setup. Every process may return zero, yet the caller still observes an unbalanced pipeline.
The useful first receipt is therefore a table, one row for each shard: process exit status, reported test count, observed file or test names, wall time and artifact path. The receipt must state the command and the runner version too. A number such as 8.2s without those fields is a stopwatch reading, not a test distribution.
Playwright Test's default reporters and a custom reporter can expose different views of the same run. The HTML, list and line reporters are display choices; the blob reporter exists for later merging and keeps structured results rather than replacing a failing shard with a green aggregate. Keep the raw shard output as a diagnostic sidecar and the blob as the merge input.
The owned two-shard experiment
The owned fixture contained four test files with deliberately unequal page timers: slow-a at 900 milliseconds, slow-b at 170 milliseconds, fast-a at 90 milliseconds and fast-b at 70 milliseconds. It ran two shards with one worker per shard using Playwright 1.58.0, stock Chrome 158.0.8127.37 and macOS arm64. The run used the same suite, browser path and test timers in both modes:
| Configuration | Shard 1 observed files | Shard 1 seconds | Shard 2 observed files | Shard 2 seconds |
|---|---|---|---|---|
| file-level | fast-a, fast-b | 7.4 | slow-a, slow-b | 8.3 |
| fullyParallel | fast-a, fast-b | 7.6 | slow-a, slow-b | 8.3 |
With one test in each file, this fixture could compare the two mode runs only at file-assignment and aggregate-report level; it did not exercise distribution of multiple tests inside one file. Shard 1 received the two fast files and shard 2 received the two slow files in both modes. Neither run sorted files by previous duration, and each shard still used one worker.
The merge step combined two blob archives per mode. The file-level four-test report recorded pass names fast-a, fast-b, slow-a and slow-b; the fullyParallel report recorded the same four names. Both aggregate runs exited zero. That is test accounting, not a claim that CI end-to-end time equals the sum of shard wall times: browser startup, artifact copying and queue delay can add overhead outside the test process.
The timing table also shows why a run should not be optimized from one sample. All four mode-and-shard jobs entered one bounded pool of four, so their wall times include competition for the same 16-core macOS machine. The assignment and complete test set remained the invariant; use repeated runs and medians when comparing CI balance, and treat one faster measurement as a hypothesis rather than an improvement.
A balanced shard table does not explain elevated CI cost by itself. Compare queue wait, browser startup and artifact upload time in the same receipt. A shard that finishes its tests quickly can still hold a pipeline open while a trace archive uploads. Conversely, adding workers to a slow test file can shorten the test process while increasing memory pressure and causing an adjacent container to evict.
The merged report has its own processing time. In the owned run, merging two blob reports took 0.672s for file-level and 0.568s for fullyParallel, while the HTML or another reporter may add file generation time later. Those numbers belong to the report job, not to the browser or the test. Keep the merge's start, input count and finish together so a slow report download is not misclassified as a slow test.
Artifact names also carry operational meaning. Use a stable prefix such as shard-1-report.zip, include the retry number when policy permits it, and prevent a later attempt from overwriting the first failure. The artifact identifier should let a reviewer join the CI job to the shard row without opening the archive. Do not encode account names, temporary tokens or private URLs in a public report name.
The safest first correction is often assignment rather than concurrency. Split a long file into independently meaningful tests only when each test owns its own visible behavior and cleanup. Do not slice one workflow into disconnected pieces just to flatten a shard bar; a test that no longer proves the user journey is not a better test. The test-fixture and isolation model provides the ownership boundary for that split.
Repeated shard measurements should keep the selected test count, browser version, worker count and artifact policy in one table. Change one row at a time. If shard duration falls but the merged report no longer contains every expected case, the experiment has reduced test coverage rather than improved scheduling.
Read the distribution before increasing workers
Start with the actual set of files or tests assigned to each shard. A file-level distribution can put two short tests and one long test in the same bucket without showing the imbalance until the shard begins. If fullyParallel is enabled and a file contains multiple independent tests, they become independently schedulable; the owned fixture did not cover that intra-file distribution. The parallel guide documents the setting and the worker-scoped behavior it uses.
The first useful record is not an average for the whole pipeline. Keep one row per shard and one column for the selected test names, process duration and artifact size. When a shard takes far longer than its sibling, open that receipt before touching worker configuration. The selected names reveal whether the shard simply received the expensive cases. Use the download and upload artifact hygiene guide to keep each artifact path owned by one shard and worker.
Distinguish queue time from execution time. CI may report one start and one finish for a job while the runner records a shorter test duration. A queued job that starts late can look like a slow suite if the two clocks are merged. Keep the runner's own elapsed time next to the CI job start, finish and upload timestamps; only the runner duration says how long the tests themselves took.
The test count also needs a denominator. A shard with two tests and a shard with eight are not comparable from wall time alone. Record the executed count, the selected count and the merged count after all blobs arrive. A skipped test may be intentionally absent from the executed total, but it should still be visible in the report and distinguished from a test that never reached the runner.
For repeated balancing, run the same suite three times and compare the median rather than selecting the most favorable sample. Keep the browser binary and profile, the test inventory, setup data and worker count fixed. If those change, label the run as a new experiment instead of mixing its duration into the old table.
The next correction belongs to the smallest unit that actually causes the tail. Moving one heavy file to its own shard can help a small suite, while splitting an unstable serial workflow can change what the test proves. Record why the unit was changed and keep a merged report from before and after. A lower shard duration with a missing test is a coverage regression, not a scheduling improvement.
Do not assume fullyParallel guarantees a balanced shard. It changes test scheduling inside the run; sharding still allocates the selected test set among jobs. The small fixture above showed a fast/slow file split under both modes, so the result is a warning against claiming a setting alone solves CI balance. A real suite needs repeated assignment records and real durations.
Workers are a second independent control. One shard with four slow tests and workers: 1 runs them serially. Raising workers may shorten that job, but it also increases CPU, memory and browser-process demand. Record the configured worker count, the observed process concurrency and the available memory before saying the job is faster. A noisier machine can turn a short queue into a resource-induced timeout.
Use the resource-planning guide when browser workers compete for a fixed CI container. Use the flaky-test attribution guide when a shard passes on retry; unequal timing and an unstable test are different diagnoses and require different evidence.
The practical tuning order is: inspect assignment, run repeated shard timings, then change one of shard count, fullyParallel or worker count. Keep the test inventory fixed in the comparison. If the suite gains or loses a test between runs, separate that change from the scheduling change before drawing a balance conclusion.
Merge reports without losing a test
Each shard can write its own blob report. The merge-reports command consumes the available blob files and produces a combined report. Upload artifacts from every shard, including failed and cancelled shards, then run the merge in a job that depends on all of them.
Do not place every shard at the same output filename without partitioning its directory or artifact name. The merge needs distinguishable files, and a CI artifact downloader may overwrite a duplicate name silently. Make the shard identifier part of the path, then assert the number of blob files before merging.
The merge result must answer three questions: how many tests ran, which cases passed or failed, and whether every expected shard contributed a report. An aggregate that says 4 passed is insufficient when only one of two blobs was downloaded. Record the input blob count and the intended test count separately, then compare both with the merged report.
Failures belong in the same merged report. A CI workflow that skips report upload when a shard fails removes exactly the evidence needed to explain a partial run. Use an artifact upload step that runs on failure when policy allows it, keep the first failure, and merge the failed blob with the others. A retry policy that overwrites an earlier artifact remains a separate evidence-loss problem.
The merged report is a presentation layer over the shard results. Keep the shard exit codes and source artifacts available for later inspection. The aggregate can be convenient to browse, but it cannot recover a blob that was never uploaded, prove that an empty shard had zero selected tests or reconstruct a test cancelled before it wrote a result.
Preserve the CI boundary
BotBrowser can supply a declared browser executable and profile to an authorized Playwright job, which helps keep the browser environment explicit across shards. It does not know which tests the runner selected, how long the CI queue was or whether the artifact service retained every blob. Record those values around the browser, not as browser capabilities.
Use a fresh BrowserContext for tests that may write storage, and avoid sharing one user-data directory across concurrent shards. A shard-specific artifact directory and context lifecycle isolate test output from another shard's file names. This is a test-harness boundary; it does not make two remote CI machines share memory, storage or a scheduler.
Keep secrets and private artifacts out of the public merged report. An HTML report can include trace locations, screenshots and URLs. Store the blob and HTML report in the CI service's access-controlled artifacts with a retention rule, and publish only a bounded summary when a public evidence page is required.
The executable fixture and reduced run record are the evidence:
fixture: docs/evidence/playwright-sharding-ci-balance-and-report-merging-fixture-20261119.cjs
run: docs/evidence/playwright-sharding-ci-balance-and-report-merging-run-20261119.json
The fixture creates four owned pages, runs two shards, writes one blob per shard per mode and merges each pair with merge-reports. The record retains the command, fixture digest, exit status, browser and Playwright versions, shard output, merged output and limits. It does not call a CI provider, upload a private artifact or establish production test execution.
For a failing job, preserve the first failing test event before cleanup. The shard exit code, merged exit code and missing blob count are separate observations. Write each field explicitly so a later reader can distinguish an uneven but successful run from a shard that never delivered its results.
FAQ
Does --shard=1/2 balance slow and fast test files?
No. It selects a subset according to Playwright's sharding rules. Measure the actual assignment and wall time; the sharding option alone does not read prior durations and build equal buckets.
Does fullyParallel make every shard finish together?
No. It changes parallel scheduling inside the run, including whether tests within a file can be spread across workers. Shards can still receive unequal files or test durations.
What does merge-reports actually merge?
It combines structured blob reports from multiple shard runs into one report. The CI job must first collect and retain those blobs, including failed shards.
Can I use the merged pass count instead of checking artifacts?
No. The merged pass count describes the blobs it consumed. Record the expected shard count and test count to detect a missing or incomplete upload.
Practical conclusion
Diagnose a slow shard from assignment and repeated timing, not from the aggregate pass count. Compare the selected files or tests, shard wall time and worker count, then change one scheduling control while keeping the suite stable. Upload one distinguishable blob per shard, merge every shard including failures, and reconcile the input blobs with the tests in the merged report. A green merge is useful only when it accounts for every expected shard.
Sources
This article is part of the guide: Browser Automation Getting Started: A First Run Map
Related Articles
Browser Automation Download and Upload Test Hygiene
Getting StartedPlaywright Download Event, saveAs and the File Path
Getting StartedSelenium WebDriver Waits for Stable Tests
Getting StartedSelenium Browser Profile Integration and Session Ownership
Getting StartedPlaywright Console Logs Not Showing? Check the Listener
Getting StartedBrowser Automation Test Fixtures and Isolation
Run the same check in BotBrowser
Load a profile, keep the signals you just read about consistent inside the browser, and confirm the result on your own machine before a rollout.