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
| Control | Effect |
|---|---|
fullyParallel | Parallelize tests inside a file |
workers | Process count |
shard | Split suite across machines |
test.describe.configure(\{ mode \}) | parallel / serial |
| Project dependencies | Setup 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/3Limit parallelism for a file:
test.describe.configure({ mode: 'default' }); // file-level sequential workersWorker 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: 1everywhere 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
serialmode.