119 / 139 · 13 Browser Automation with Playwright · Parallel Execution and Reporting← prev⊞ allnext →☰ Read as one page
14.2Parallel Execution
Playwright runs tests in parallel by default using worker processes. Each worker gets its own browser instance with isolated contexts.
How Workers Work
Worker 1: login.spec.ts → runs all tests in file sequentially
Worker 2: checkout.spec.ts → runs all tests in file sequentially
Worker 3: search.spec.ts → runs all tests in file sequentially
Worker 4: admin.spec.ts → runs all tests in file sequentially
By default, tests in the same file run sequentially; tests in different files run in parallel across workers.
// playwright.config.ts
export default defineConfig({
workers: process.env.CI ? 4 : undefined, // undefined = half CPU cores
fullyParallel: true, // Also parallelize tests within a file
});
Controlling Parallelism
// Run specific tests sequentially (e.g., tests that share external state)
test.describe.serial('payment flow', () => {
test('add to cart', async ({ page }) => { /* ... */ });
test('enter shipping', async ({ page }) => { /* ... */ });
test('complete payment', async ({ page }) => { /* ... */ });
});
// Configure workers per project
export default defineConfig({
projects: [
{ name: 'chromium', use: { browserName: 'chromium' } },
{ name: 'api-tests', testMatch: /.*\.api\.ts/, workers: 8 }, // More workers for API tests
],
});