25. Dependency Injection with Custom Playwright Fixtures

Creating Custom POM Fixtures in JavaScript

// 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";

Task

  • Implement buildFixtureConfig:
  • 1. Accept fixtureName string.
  • 2. Return { name: fixtureName, scope: "test" }.
πŸ’‘Common doubts
Did you like the problem?
Lesson 25 of 35
JavaScript
Loading code editor…
Next