Sobes.tech
Middle

What is a Page Object? Tell me about the pattern.

sobes.tech AI

Answer from AI

Page Object is a design pattern widely used in UI test automation. Its essence is that for each page (or a significant component of a page), a separate class is created that encapsulates the logic of interacting with the elements of that page.

This allows:

  • Isolating locators and methods for working with elements from tests.
  • Making tests more readable and maintainable.
  • Simplifying support when the interface changes — just update the Page Object.

Example in Python with Selenium:

class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.username_input = driver.find_element_by_id('username')
        self.password_input = driver.find_element_by_id('password')
        self.login_button = driver.find_element_by_id('login')

    def login(self, username, password):
        self.username_input.send_keys(username)
        self.password_input.send_keys(password)
        self.login_button.click()

Tests use this class without worrying about the details of locators.