Code Reference

Parallel

Playwright · Reference cheat sheet

Parallel

Playwright · Reference cheat sheet


📋 Overview

Playwright runs tests in parallel across workers and shards. Isolate state, avoid shared mutable resources, and tune workers for CI hardware.

🔧 Core concepts

ControlEffect
fullyParallelParallelize tests inside a file
workersProcess count
shardSplit suite across machines
test.describe.configure(\{ mode \})parallel / serial
Project dependenciesSetup before dependents

Each worker gets its own browser; contexts isolate cookies/storage.

💡 Examples

Config:

export default defineConfig({
  fullyParallel: true,
  workers: process.env.CI ? 2 : undefined,
});

Serial describe (order matters):

test.describe.configure({ mode: 'serial' });
test.describe('checkout flow', () => {
  test('add to cart', async ({ page }) => { /* ... */ });
  test('pay', async ({ page }) => { /* ... */ });
});

Sharding in CI:

npx playwright test --shard=1/3
npx playwright test --shard=2/3
npx playwright test --shard=3/3

Limit parallelism for a file:

test.describe.configure({ mode: 'default' }); // file-level sequential workers

Worker index for unique data:

test('unique user', async ({}, testInfo) => {
  const email = `user-${testInfo.parallelIndex}@ex.com`;
});

⚠️ Pitfalls

  • Shared DB rows / accounts without unique keys → cross-test collisions.
  • workers: 1 everywhere hides local parallelism bugs until CI.
  • Serial suites that are unnecessarily long — prefer independent tests.
  • Uneven shards when heavy tests cluster in one file.
  • Relying on test order outside serial mode.

On this page