How do I run Playwright tests in parallel, and what are workers?
Written by Jatin Thacker, Automation Architect · Updated
--workers or the workers config option, and you let tests inside one file run in parallel with fullyParallel: true or test.describe.configure({ mode: 'parallel' }).This answer is one piece of Chapter 16: The Test Runner.
- Test Structure & Lifecycle
- playwright.config.ts Complete Reference
- Test Organization at Scale
- Tags, Grep, and the Suite You Actually Run
- What Runs Where, and What Serial Costs
- Practice and interview questions: Assertions & Test Runner
A worker is an independent process that the test runner starts and hands tests to. Each worker launches its own browser, and workers cannot talk to each other, so parallel tests must not share state or global variables. That isolation is what makes parallel runs safe.
By default, different files run at the same time in different workers, but the tests inside one file run in order in the same worker. Two switches change that. fullyParallel: true in the config spreads every test across workers. test.describe.configure({ mode: 'parallel' }) does the same for one file.
The number of workers is a limit you choose. --workers=2 on the command line, or workers: process.env.CI ? 2 : undefined in the config, caps it. --workers=1 turns parallelism off, which is useful when you suspect two tests are interfering.
The example puts four page checks in one file, opts that file into parallel mode and runs it with two workers. The log shows the tests shared out between worker 0 and worker 1, read from testInfo.workerIndex.
import { test, expect } from '@playwright/test';
test.describe.configure({ mode: 'parallel' });
for (const path of ['/catalog.html', '/orders.html', '/api-lab.html', '/login.html']) {
test(`opens ${path}`, async ({ page }, testInfo) => {
await page.goto(`${path}?mock=static&seed=42&autologin=1`);
await expect(page.getByTestId('site-header')).toBeVisible();
console.log(`${path} ran on worker ${testInfo.workerIndex}`);
});
}$ npx playwright test parallel.spec.js --workers=2 Running 4 tests using 2 workers /catalog.html ran on worker 0 /orders.html ran on worker 1 ok 1 [chromium] › parallel.spec.js:6:3 › opens /catalog.html (650ms) ok 2 [chromium] › parallel.spec.js:6:3 › opens /orders.html (644ms) /api-lab.html ran on worker 0 /login.html ran on worker 1 ok 3 [chromium] › parallel.spec.js:6:3 › opens /api-lab.html (439ms) ok 4 [chromium] › parallel.spec.js:6:3 › opens /login.html (443ms) 4 passed (2.8s)
--workers=4. How do those five tests run?Practised in the full course: the drill fullyParallel backwards.
See the chapterRelated questions
AI can write the test now. The job is knowing whether it checks anything. That's what the course teaches, one chapter at a time.
163 lessons · 226 drills · start free