Lesson 23 / 25
Parallelism and Sharding
Workers inside a machine, shards across machines.
Splitting the work
Playwright runs test files in parallel workers on one machine (workers in config; fullyParallel: true also parallelises tests within a file). To spread a suite across machines, use sharding: npx playwright test --shard=1/4 runs a quarter of the tests; a CI matrix runs each shard, and with the blob reporter the per-shard results can be combined with npx playwright merge-reports. Cypress runs spec files serially within one cypress run; parallelisation across machines is provided by Cypress Cloud (cypress run --record --parallel, a paid service beyond the free tier) or by community tools that split specs between CI jobs. Parallel runs only work if tests are isolated and do not share data.
Sharding Playwright in a matrix
Each job runs one shard and uploads a blob report.
jobs:
e2e:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test --shard=${{ matrix.shard }}/4 --reporter=blob
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: blob-report-${{ matrix.shard }}
path: blob-report
# a follow-up job downloads all blob-report-* artifacts and runs:
# npx playwright merge-reports --reporter html ./all-blob-reportsMore checkout lanes
Workers open more tills in one shop; shards open more shops. Either way, each customer (test) must be able to pay without waiting for the person in front.
Quick check: What does `npx playwright test --shard=2/4` do?
- Runs the second of four roughly equal portions of the suite
- Runs every test four times
- Uses two workers for four browsers
- Skips half of the tests permanently
Answer
Runs the second of four roughly equal portions of the suite — Combine shards with a CI matrix and merged reports.