TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
Playwright / Chapter 48 of 60~18 min • Beginner
Chapter 48Playwright

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

  1. Create a custom fixture
  2. Pass a value with use
  3. Consume it in a test

Example

TypeScript
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');
});
Expected result: Custom fixture test passes
💡 Point to remember
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