POM Does Not Mean One Class for Every Small Action

A common beginner mistake is creating too many tiny methods.

For example:

clickUsername();
clickPassword();
typeUsername();
typePassword();
clickLogin();

This can make the framework unnecessarily complicated.

Instead, group actions that represent a meaningful user operation.

For example:

async login(username: string, password: string) {
    await this.username.fill(username);
    await this.password.fill(password);
    await this.loginButton.click();
}

This represents one meaningful business action:

Login


Should Assertions Be Inside Page Objects?

This depends on your framework design.

A simple approach is to keep most test-specific assertions inside the test.

For example:

await loginPage.login('testuser', 'password123');

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

The test clearly shows what result is expected.

However, reusable page-level validation methods can also be useful.

For example:

async expectDashboardVisible() {
    await expect(this.dashboard).toBeVisible();
}

The important thing is to keep your framework consistent.


Common POM Mistakes

Mistake 1: Creating Huge Page Classes

Don’t put every application operation into one massive class.

For example:

LoginPage.ts
    login()
    search()
    addToCart()
    checkout()
    logout()
    updateProfile()

If these actions belong to different pages or modules, separate them.


Mistake 2: Using Weak Locators

POM doesn’t automatically make bad locators good.

Prefer stable locators such as:

page.getByRole()
page.getByLabel()
page.getByPlaceholder()
page.getByTestId()

when they fit the application.


Mistake 3: Repeating the Same Code

If your page object contains:

async login()
async loginUser()
async performLogin()

and all three methods do the same thing, you probably have unnecessary duplication.

Keep the design simple.


Mistake 4: Making Tests Too Dependent on Implementation Details

Your test should ideally describe user behavior.

For example:

await loginPage.login(username, password);

is easier to understand than exposing every low-level interaction in every test.


Pages: 1 2 3 4 5 6 7

Leave a Reply

Your email address will not be published. Required fields are marked *