Playwright·Cookbook Field Manual
Part 05 · Operations & Advanced Card 30

CI Sharding & Merge Reports

Card 30: CI Sharding & Merge Reports

What This Pattern Solves

Real suites need sharding: split tests across N CI machines, each running a subset, then merge the per-shard reports into one. This repo ships a working implementation: a sharded .github/workflows/playwright.yml plus a blob reporter that only turns on under CI.

How It Works

  1. Blob reporter writes each shard’s results to a portable file (enabled only on CI).
  2. --shard=N/M splits tests evenly by filename across the matrix.
  3. merge-reports combines all the shard blobs into a single HTML report in a follow-up job.

Code Example

playwright.config.ts (CI emits a blob report; the HTML report comes from the merge step):

const isCI = !!process.env.CI;

export default defineConfig({
  workers: isCI ? '50%' : undefined,
  reporter: isCI
    ? [['list'], ['blob'], ['junit', { outputFile: 'test-results/junit.xml' }]]
    : [['html']],
});

.github/workflows/playwright.yml — a shard matrix uploads one blob per shard, then a merge-reports job downloads them all and merges into HTML:

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3, 4]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pnpm install --frozen-lockfile
      - run: pnpm exec playwright install --with-deps chromium
      - run: pnpm exec playwright test --shard=${{ matrix.shard }}/${{ strategy.job-total }}
      - name: Upload blob report
        if: ${{ !cancelled() }}
        uses: actions/upload-artifact@v4
        with:
          name: blob-report-${{ matrix.shard }}
          path: blob-report

  merge-reports:
    if: ${{ !cancelled() }}
    needs: [test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pnpm install --frozen-lockfile
      - uses: actions/download-artifact@v4
        with:
          path: all-blob-reports
          pattern: blob-report-*
          merge-multiple: true
      - run: pnpm exec playwright merge-reports --reporter html ./all-blob-reports
      - uses: actions/upload-artifact@v4
        with:
          name: playwright-html-report
          path: playwright-report

Run This Example

pnpm test src/30-ci-sharding-and-merge-reports
npx playwright test --shard=1/4 --reporter=blob
npx playwright merge-reports --reporter=html ./all-blob-reports

Key Concepts

Live Demo

👇 This component is what the Playwright test interacts with:

Loading…

Run This Example

pnpm test src/30-ci-sharding-and-merge-reports