Custom Fixtures in Playwright
From the Playwright cheat sheet ยท Fixtures & Page Object Model ยท verified Jul 2026
Custom Fixtures
Create reusable test fixtures for shared setup logic
typescript
import { test as base, expect } from '@playwright/test';
// Define custom fixture
const test = base.extend<{ todoPage: TodoPage }>({
todoPage: async ({ page }, use) => {
const todoPage = new TodoPage(page);
await todoPage.goto();
await use(todoPage);
},
});
test('can add todo', async ({ todoPage }) => {
await todoPage.addTodo('Buy milk');
await todoPage.expectTodoVisible('Buy milk');
});๐ก Page Objects encapsulate page interactions โ tests read like user stories
โก Custom fixtures handle setup and teardown automatically for every test that uses them
๐ Export your extended test and expect from a shared file so all tests use the same fixtures
๐ข The use() callback marks where the test runs โ code after it is teardown logic
fixturespage-objectpom