Using Page Object Models (POMs) as fixtures in @playwright/test provides several benefits:
To organize fixtures in multiple files, you can create separate TypeScript files for each fixture and import them into your test files. Here's an example:
fixtures.ts
file with your POM fixture:import { test as baseTest } from '@playwright/test';
export const test = baseTest.extend<{ pageModel: PageModel }>({
pageModel: async ({ page }, use) => {
const pageModel = new PageModel(page);
await use(pageModel);
},
});
PageModel.ts
file with your POM class:import { Page } from '@playwright/test';
export class PageModel {
constructor(private page: Page) {}
async navigate() {
await this.page.goto('https://ray.run/');
}
async getTitle() {
return await this.page.title();
}
}
test
fixture and PageModel
class in your test file:import { test, expect } from './fixtures';
import { PageModel } from './PageModel';
test('Check page title', async ({ pageModel }) => {
await pageModel.navigate();
const title = await pageModel.getTitle();
expect(title).toBe('Ray.run');
});
By organizing your POM fixtures and classes in separate files, you can easily manage and scale your test suite.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].