PrometheeSelenium
Download

Page Object Model (POM)

The Page Object Model is a design pattern that creates an object repository for storing all web elements. Promethee-Selenium natively builds on this to reduce code duplication and improve test maintenance.

The Concept

For each UI page of an application, a corresponding page class is created. This page class is responsible for finding the WebElements of that page and executing operations on them.

Implementation

To implement your own page object, inherit from our Base class available in Promethee.

Example

from promethee.core.base import Base
from selenium.webdriver.common.by import By

class LoginPage(Base):
    def __init__(self, driver):
        super().__init__(driver)
        
        self.username_input = (By.ID, "user-name")
        self.password_input = (By.ID, "password")
        self.login_button = (By.ID, "login-button")
        
    def login(self, username, password):
        self.type_text(self.username_input, username)
        self.type_text(self.password_input, password)
        self.click_element(self.login_button)

Benefits

  • Maintainability: Update the locator in the page class instead of replacing it in every test.
  • Reusability: Write the code once to get the element or perform an action, and use it across multiple scripts.
  • Readability: Test scripts read more like actual user scenarios.