Skip to main content

Introduction

Playwright Test runs tests in parallel by default using multiple worker processes. This significantly reduces test execution time.

How Parallelization Works

From src/common/config.ts:121,240-252 and src/runner/testRunner.ts:88-115: Playwright uses a worker-based parallelization model:
  1. Test runner spawns multiple worker processes
  2. Each worker runs tests sequentially
  3. Workers run in parallel to each other
  4. Tests are distributed across available workers

Worker Configuration

Fixed Number of Workers

Percentage of CPU Cores

From src/common/config.ts:240-252:

Automatic Detection

Environment-Based Configuration

Parallel Modes

From src/common/test.ts:58 and src/common/testType.ts:46-51,155-168:

Default Mode

Tests within a file run sequentially:
Different files run in parallel:

Fully Parallel Mode

Run all tests in parallel: From src/common/config.ts:102:
Or per-project:

Describe Parallel

Make specific describe blocks run in parallel: From src/common/testType.ts:47,155-158:

Serial Mode

Force tests to run serially: From src/common/testType.ts:49,155-156:
describe.parallel cannot be nested inside describe.serial or default mode describe blocks.

Worker Isolation

Each worker maintains its own isolated environment:

Worker-Scoped Fixtures

Shared within a worker, isolated between workers:

Browser Instance Sharing

From src/index.ts:104-126: Browser instances are shared within workers:
Each worker:
  • Launches one browser instance
  • Creates fresh contexts for each test
  • Reuses browser across tests

Controlling Parallelization

Project-Level Workers

From src/common/config.ts:212-215:

Configure Mode

From src/common/testType.ts:186-209:

Worker Index

Access worker index in tests:

Sharding

Distribute tests across multiple machines: From src/common/config.ts:116:

Configuration

CLI Usage

CI/CD Example

Test Distribution

Tests are distributed to balance execution time:

Parallel Execution Patterns

Independent Tests

Tests that don’t share state:

Shared Setup with Parallel Tests

Sequential Test Flow

Performance Optimization

Optimal Worker Count

Test Organization

Browser Reuse

Worker-scoped browser fixture reuses browsers:

Debugging Parallel Tests

Run Tests Serially

View Worker Output

Test Info Debugging

Common Pitfalls

Shared Mutable State

File System Operations

Database Conflicts

Best Practices

  1. Design for parallelization: Make tests independent
  2. Use appropriate worker count: Balance speed and resources
  3. Avoid shared state: Each test should be self-contained
  4. Use worker-scoped fixtures: For expensive setup
  5. Leverage sharding: For very large test suites
  6. Monitor CI resources: Adjust workers based on available CPU
  7. Use serial mode sparingly: Only when necessary

Example: Optimal Configuration

Next Steps

Retries

Learn about test retries

Configuration

Configure worker settings