← Back to libraryQuestion 286 of 468
🏗️Framework DesignIntermediate

Page Object Model (POM)

📌 Definition:

The Page Object Model is a design pattern where each page (or component) of the application is represented by a class that encapsulates its locators and interaction methods, so tests interact with pages through a clean API rather than raw locators.

📖 Detailed Explanation:

In POM, a LoginPage class holds the page's element locators and exposes intent-revealing methods (login(user, pass), getErrorMessage()). Tests call loginPage.login(...) instead of finding elements directly. This centralizes locators (a UI change updates ONE class, not every test), improves readability (tests read as business steps), and promotes reuse. Best practices: page methods return page objects (enabling fluent chaining) or data, keep assertions OUT of page objects (they belong in tests), and model reusable components (header, modal) as their own objects. POM is the single most-asked framework-design pattern.

🔑 Key Points:
  • Each page = a class encapsulating locators + actions
  • Tests use page methods (login()), not raw locators
  • Locator change → update ONE class (maintainability)
  • Keep assertions in tests, not in page objects
🌍 Real-World Example:

When the login button's id changes, only LoginPage.LOGIN_BTN is updated; the 40 tests that call loginPage.login(...) keep working unchanged — the core maintainability win of POM.

🎯 Scenario-Based Interview Question:

Why should assertions live in the test and NOT inside Page Object methods?