Playwright Fixtures Deep Dive — Test Setup Done Right (2026)
Master Playwright fixtures: worker-scoped auth, per-test data seeding, custom pages, and the fixture composition patterns that eliminate beforeEach boilerplate.

Last updated 2026-07-20 · 11 min read · By Avinash Kamble, reviewed by Priyanka G.
beforeEach hooks are Playwright's biggest smell. Fixtures replace them with typed, composable, worker-scoped setup that runs faster and reads cleaner. Once your team internalizes fixtures, PR reviews get 30% shorter because setup is centralized.
Key takeaways
- The 3 fixture scopes (test, worker, project) and when to use each.
- Worker-scoped auth: sign in once per worker, save 90% of setup time.
- Fixture composition — extend from base to feature suites.
- Fixture teardown for cleanup that always runs.
1. Three fixture scopes
| Scope | Lifetime | Use for |
|---|---|---|
| test | per test | fresh data, page objects |
| worker | per worker process | auth state, DB pools, browser context |
| project | per test project | shared config, feature flags |
2. A custom fixture from scratch
// fixtures.ts
import { test as base } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
type MyFixtures = { loginPage: LoginPage; seededOrder: { id: string } };
export const test = base.extend<MyFixtures>({
loginPage: async ({ page }, use) => {
await use(new LoginPage(page));
},
seededOrder: async ({ request }, use) => {
const order = await request.post('/api/orders', { data: { total: 100 } });
await use(await order.json());
await request.delete('/api/orders/' + (await order.json()).id);
},
});
export { expect } from '@playwright/test';Now every test that needs a seeded order gets one — and cleanup runs automatically after the test.
3. Worker-scoped auth — the 10x speedup
// auth.setup.ts — runs once, produces storageState.json
setup('authenticate', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill(process.env.TEST_USER);
await page.getByLabel('Password').fill(process.env.TEST_PASS);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.context().storageState({ path: 'auth.json' });
});
// playwright.config.ts
projects: [
{ name: 'setup', testMatch: /auth\.setup\.ts/ },
{
name: 'chromium',
use: { storageState: 'auth.json' },
dependencies: ['setup'],
},
];A 500-test suite that used to log in 500 times now logs in once per worker. Real numbers from our stack: 42 min → 8 min. See the official auth guide.
4. Composing fixtures across suites
Build a base fixture with common setup, then extend per feature: const paymentTest = test.extend({ stripeMock: ... }). Compose don't duplicate. See our POM complete guide for how fixtures + POM together replace 90% of beforeEach.
5. Teardown that always runs
Everything after await use(value) is teardown. Even if the test fails, it runs. Use this for DB cleanup, feature-flag reset, and file deletes. Cross-reference the Playwright interview questions hub — fixture teardown is asked at 60% of senior SDET interviews.
Frequently asked questions
1.Should I use beforeEach or fixtures?
2.Can a worker-scoped fixture depend on a test-scoped one?
3.How many fixtures is too many?
4.Do fixtures work with parallel workers?
Practice these questions
Drill 200+ Playwright questions with senior-SDET sample answers — locators, auto-wait, fixtures, parallelism and trace viewer.
Was this article helpful?
Keep building your QA edge
Pillar guides- Selenium PillarSelenium WebDriver guide300 Selenium WebDriver Q&A — locators, waits, frameworks.
- Playwright Installation Guidehow to install Playwright step by stepInstall Playwright the right way — Node, browsers, VS Code, first test.
- XPath & CSS Selector Generatorgenerate robust Playwright and Selenium locatorsInteractive locator generator for Playwright, Selenium and Cypress — with Page Object export.
- Automation QA Engineer RoleSoftwareTestPilot's Automation QA role pageAutomation QA Engineer job scope, tools, salary, and hiring pipeline.
- QA Skills HubSoftwareTestPilot's QA skills tracksStructured skill tracks — Selenium, Playwright, Cypress, API, JMeter, SQL, Java, Python for testers.
Practice these questions live
Rehearse with an AI QA interviewer that scores your answers in real time.
Continue reading

Playwright Locator Best Practices (2026) — The Only Guide You Need
11 min read
How to Migrate a Postman Collection to Playwright API Tests (2026 Guide)
12 min read
Why Every QA Engineer Must Master CI/CD Pipelines in 2026 (Or Risk Obsolescence)
12 min readRelated concepts, tools & standards around Automation Testing
A quick reference of the people, companies, frameworks and technologies most often mentioned alongside Automation Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.
Join the QA Community
Connect with fellow testers, share job leads, and get career advice.
Stop Reinventing the Wheel. Upgrade Your QA Arsenal.
Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.
- Ready-to-use testing strategy templates
- Advanced API & UI automation guides
- ⏱️ Save 10+ hours a week on test planning
Discussion
Ask a question, share your experience, or correct us. Be kind — real people are reading.