Fixture scopes and parallelism control how often setup runs and which tests share resources. For large suites, getting this right is critical for both speed and isolation.
Fixture Scopes and Parallel Workers
Playwright supports different fixture scopes, most commonly per-test and per-worker. Per-test fixtures run freshly for each test, while per-worker fixtures are created once per worker process and reused across tests on that worker.
// scoped-fixtures.ts
import { test as base } from '@playwright/test';
// Example of a worker-scoped fixture for expensive setup.
const test = base.extend({
globalConfig: [async ({}, use) => {
const config = { apiBaseUrl: 'https://api.demo.myshop.com' };
await use(config);
}, { scope: 'worker' }],
});
export { test };
Understanding how Playwright distributes tests across workers helps you design fixtures that balance performance with isolation.
Common Mistakes
Mistake 1 โ Using worker scope for mutable, shared state
This creates hidden couplings.
โ Wrong: Reusing a single shopping cart or user session across many tests in parallel.
โ Correct: Keep such state per test or use unique data per worker.
Mistake 2 โ Making all fixtures per-test without considering cost
This can slow down suites.
โ Wrong: Re-running extremely heavy setup thousands of times.
โ Correct: Identify safe candidates for worker scope or one-time setup.