FAQs »

Can I use the Page Object Model with my Playwright scripts?

Yes—with one twist. A Loadster Playwright script is a single, self-contained file, so it can’t import page objects from separate files the way a typical Page Object Model (POM) project does. But the pattern itself works fine when you define your page object classes in the same file as your test:

import {test, expect, type Page} from '@playwright/test';

class LoginPage {
    constructor(private page: Page) {}

    async goto() {
        await this.page.goto('https://example.com/login');
    }

    async login(username: string, password: string) {
        await this.page.getByLabel('Email').fill(username);
        await this.page.getByLabel('Password').fill(password);
        await this.page.getByRole('button', {name: 'Sign in'}).click();
    }
}

test('user can log in', async ({page}) => {
    const login = new LoginPage(page);

    await login.goto();
    await login.login('demo@example.com', 'secret');

    await expect(page).toHaveURL(/dashboard/);
});

If you already have a POM-based suite spread across multiple files, you can bring an individual test into Loadster by flattening it—inlining the page objects and helpers it uses into one script. LLMs and AI coding assistants are quite good at this kind of transformation, so it’s usually a quick paste-and-convert.

Helper functions and Playwright Test fixtures work the same way. For full examples and tips on adapting an existing test suite, see Organizing Playwright Scripts in the manual.