Back to All Questions
Question 75 of 100
Execution
Intermediate
How does Playwright run tests in parallel?
The Answer
Playwright spawns multiple worker processes that run tests simultaneously. Each worker operates independently with its own browser, browser context, and page β guaranteeing complete isolation.
Deep Dive Explanation
Worker count impacts resource usage. A good rule: set workers equal to the number of CPU cores available. In Docker-based CI, over-provisioning workers causes memory pressure and paradoxically slows down execution.
example.spec.ts
// playwright.config.ts
export default defineConfig({
// Run ALL tests across files in parallel (no ordering)
fullyParallel: true,
// Control number of workers
workers: process.env.CI ? 4 : '50%', // 4 in CI, half CPU cores locally
// Override per describe block
});
// In test file - force parallel within a file
test.describe.configure({ mode: 'parallel' });
// Run with specific workers via CLI
// npx playwright test --workers=4
// Sharding for CI (split across multiple machines)
// Machine 1: npx playwright test --shard=1/3
// Machine 2: npx playwright test --shard=2/3
// Machine 3: npx playwright test --shard=3/3