Playwright · Reliable end-to-end tests
How does test sharding work?
Short answer
--shard=1/4 runs one quarter of the suite, balanced by test file. Combine shards in a CI matrix, then merge blob reports into one HTML report.
Sharding splits the suite across separate CI jobs rather than separate workers on one machine. Each shard runs a deterministic subset, so four jobs can finish in roughly a quarter of the time if the test files are balanced.
npx playwright test --shard=1/3
npx playwright test --shard=2/3
npx playwright test --shard=3/3npx playwright test --reporter=blob
npx playwright merge-reports --reporter=html blob-reportPractical points
- Shards are balanced by test file, not by individual test
- One large slow file can dominate a shard and leave the others idle
- Use a CI matrix to launch each shard as its own job
- Upload each shard's blob report, then merge them in a final job
- Sharding multiplies shared environment cost but reduces wall-clock time
- Sharding is not a substitute for parallel workers inside a shard
If shard times are uneven, split the heavy file or move long setup work into a worker-scoped fixture. Adding more shards than there are reasonably sized files produces diminishing returns and more overhead.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1How are tests distributed across shards?
- 2Why can shard times be uneven?
- 3How do you merge reports from several shards?
- 4When does sharding stop helping?
Say it in the interview
Sharding runs a deterministic subset of the suite per CI job, so several machines can work in parallel. The split is by test file, which means one heavy file can make a shard slow. I launch the shards in a CI matrix, use blob reports and merge them into one HTML report. I keep each shard on the same app version and data setup so the merged results are comparable.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.