Sharding in Playwright: Run Tests Faster at Scale
Technology Blogs

Sharding in Playwright: Run Tests Faster at Scale

Rohit Yelgude
QA Engineer

As your application grows, so does your test suite. What started as a nimble set of 50 tests can balloon to 500, 1,000, or even several thousand end-to-end scenarios. Running them all sequentially becomes a bottleneck, a single pipeline can eat up 30, 45, even 60 minutes of CI time. Your developers sit idle. Feedback loops stretch. Velocity suffers.

Playwright’s built-in sharding feature solves this elegantly. Instead of running all tests on a single machine, you split, or shard, your suite across multiple parallel workers, each running an independent slice. The result: dramatically faster pipelines with no extra code and minimal configuration.

This post dives deep into how sharding works, how to configure it, how to merge reports from multiple shards, and real-world tips for getting the most out of it in CI/CD environments.

What exactly is sharding?

Sharding is the concept of dividing a dataset, in this case, your test suite, into multiple equal (or near-equal) partitions called shards. Each shard contains a subset of tests and is executed independently, typically on a separate machine or container running in parallel.

Playwright implements sharding at the CLI level using two parameters: –shard=<index>/<total>. The total represents how many shards to split the suite into, and index (1-based) identifies which shard the current runner should execute.

Think of it like a deck of cards. Sharding deals the cards equally across N players, each player plays their hand independently, and together they finish the whole deck in a fraction of the time.

Playwright distributes test files across shards by alphabetical order of file path. Each shard picks up roughly total_files / N test files, ensuring balanced coverage without duplication.

How shards split your tests

Shard 1/4Shard 2/4Shard 3/4Shard 4/4
auth.spec.ts, cart.spec.tscheckout.spec.ts, dashboard.spec.tslogin.spec.ts, orders.spec.tsproducts.spec.ts, search.spec.ts

The basic syntax

Running a specific shard is a single flag appended to your Playwright command. No plugins, no extra packages, it works out of the box.

# Run shard 1 of 3
npx playwright test --shard=1/3

# Run shard 2 of 3
npx playwright test --shard=2/3

# Run shard 3 of 3
npx playwright test --shard=3/3

Setting up sharding in GitHub Actions

GitHub Actions makes parallel sharding seamless via the strategy.matrix feature. The matrix spins up N independent runner jobs, each receiving its shard index as an environment variable.

strategy:
  fail-fast: false
  matrix:
    shard: [1, 2, 3, 4]

- name: Run Playwright tests
  run: npx playwright test --shard=${{ matrix.shard }}/4

Notice fail-fast: false this ensures that if one shard fails, the others continue running. This gives you a complete picture of all failures rather than cutting short on the first broken shard.

Modernize Your QA Automation Pipeline, Talk to Us.

Merging reports from all shards

When shards run in parallel, each produces its own report. Playwright’s blob reporter was introduced specifically to handle this: each shard outputs a raw binary blob, and after all shards complete, you merge them into a unified HTML report.

First, configure the blob reporter in your playwright.config.ts:

reporter: [
  ['blob', { outputDir: 'blob-report' }]
]

Then in a follow-up CI job, download all blob artifacts and run:

npx playwright merge-reports --reporter html ./all-blob-reports

How many shards should you use?

4x

typical speedup with 4 shards
on 200+ test suites

~80%

CI time reduction with 500+ tests

1:1

ideal ratio: one shard per CI
runner

A few rules of thumb for choosing your shard count:

  • Start with 1 shard per 2-3 minutes of your current total runtime. If your suite takes 20 minutes sequentially, try 8 shards to target a ~3 min pipeline.
  • Match shards to available runners. More shards than runners wastes allocation, idle queued jobs negate the benefit.
  • Monitor shard duration variance. If one shard consistently takes 3x longer, your test distribution may be uneven.
  • For very large suites (1,000+ tests), combine sharding with -workers (parallelism within a shard) for maximum throughput.

Sharding vs. parallelism: the key difference

Playwright supports two orthogonal forms of concurrency that are often confused:

Parallelism (within a machine)Sharding (across machines)
Controlled by workers in playwright.config.ts. Runs multiple test files simultaneously on the same machine using separate browser processes.Controlled by –shard flag. Splits the test suite across multiple machines in your CI matrix. Each machine runs its slice independently.

You can and often should combine both. Set workers: 4 in your config, and run 4 shards in CI. That’s 4 × 4 = 16 concurrent test workers total.

Common pitfalls and how to avoid them

Shared state and test isolation: Sharding only works when your tests are truly independent. Tests that share a database, user session, or global state will produce flaky results. Ensure each test creates and cleans up its own data, or uses isolated environments.

Uneven shard distribution: Playwright distributes by file, not by individual test count or execution time. If a few files are much heavier, some shards will finish quickly while one runs far longer. Split heavy files into smaller ones to rebalance.

Missing if: always() on artifact upload: If a shard fails and you don’t upload its blob report, the merge step won’t have complete data. Always use if: always() on your upload steps.

Real-world impact

Teams with mature Playwright setups routinely report dramatic improvements after adopting sharding. A suite that took 45 minutes on a single runner can be reduced to under 8 minutes with 6 shards. More importantly, the feedback loop for developers shortens significantly, pull requests that previously waited an hour for test results now get feedback in under 10 minutes.

The real value of sharding isn’t just speed, it’s the cultural shift it enables. When CI feedback arrives rapidly, developers stop batch-merging PRs, test suites stay healthier, and shipping confidence rises.

Conclusion

Playwright’s sharding support is one of its most production-ready features zero-dependency, tightly integrated, and powerful enough to scale from a mid-sized startup’s test suite to an enterprise monolith’s thousands of end-to-end tests. The combination of the –shard CLI flag, the blob reporter, and merge-reports gives you a complete, first-class solution for distributed test execution without reaching for third-party tooling.

Start with 4 shards, monitor the duration balance, and adjust. Your developers and your CI bill will thank you.

Rohit Yelgude

Rohit Yelgude

QA Engineer

Rohit Yelgude is a QA Lead with 5+ years of experience in software quality assurance. At Mindbowser, he specializes in API testing, mobile testing, UI/UX validation, and test automation, helping teams deliver reliable, high-quality digital products.

Share This Blog

Read More Similar Blogs

Let’s #Transform Healthcare,# Together.

Partner with us to design, build, and scale digital solutions that drive better outcomes.

Contact form