Playwright + JS · Lesson 25 of 35
Module 25: Fixtures
Try it yourself
Implement buildFixtureConfig:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
// fixtures/myTest.js
import { test as base } from "@playwright/test";
import { LoginPage } from "../pages/LoginPage.js";
export const test = base.extend({
loginPage: async ({ page }, use) => {
const loginPage = new LoginPage(page);
await use(loginPage);
// Teardown occurs automatically here!
},
});
export { expect } from "@playwright/test";Playwright Fixtures provide modular dependency injection for your test suites. Instead of manual setup and teardown in every test file, custom fixtures instantiate Page Objects, set up database records, and automatically tear down resources. Let's build custom fixtures!
Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Test-scoped fixtures run once per test for maximum isolation. Worker-scoped fixtures run once per worker process (e.g. expensive database seeding).
Finished reading?
Review the worked example in the editor, then mark the lesson complete.