Chapter 48: Fixtures and isolation
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Fixtures and isolation
Fixtures provide dependencies and manage setup and teardown. The built-in page fixture gives each test an isolated page in a fresh context. Custom fixtures use test.extend and await use(value) to supply a resource to the test.
How it works
Step-by-step walkthrough
- Create a custom fixture
- Pass a value with use
- Consume it in a test
Example
import { test as base, expect } from '@playwright/test';
const test = base.extend<{ greeting: string }>({
greeting: async ({}, use) => { await use('Hello QA'); }
});
test('greeting', async ({ greeting }) => {
expect(greeting).toBe('Hello QA');
});Do not share mutable state across tests without a deliberate design.
✎ Your practice task
Create a fixture that provides an array of test data.
Knowledge check
What supplies a custom fixture value?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.