
Page Object Model. Why you need them.
August 17, 2024
What is Page Object Model?
The Page Object Model (POM) is a design pattern in test automation that creates an object repository for web UI elements. Each web page in the application has a corresponding page class that contains the elements and methods of that page.
Why Use Page Object Model?
- Improved maintainability
- Enhanced readability
- Code reusability
- Separation of concerns
- Scalability
Example Implementation
class LoginPage {
constructor(page) {
this.page = page;
this.usernameInput = page.locator('#username');
this.passwordInput = page.locator('#password');
this.loginButton = page.locator('button[type="submit"]');
}
async login(username, password) {
await this.usernameInput.fill(username);
await this.passwordInput.fill(password);
await this.loginButton.click();
}
}