Page Object Pattern in Python - Codoid
Select Page
Automation Testing

Page Object Pattern in Python

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

Listen to this blog

Page objects are commonly used for testing, but should not make assertions themselves. Their responsibility is to provide access to the state of the underlying page. It’s up to test clients to carry out the assertion logic.

Martin Fowler

In this blog article, you will learn how to implement Page Object Pattern using PyPOM package.

Installation

pip install PyPOM
  

[/code]

Sample Code

from pypom import Page
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path='driverschromedriver.exe')

class Home(Page):
    _contact_us_locator = (By.ID, 'menu-item-54')

    @property
    def fill_contact_us_form(self):
        self.find_element(*self._contact_us_locator).click()

base_url = 'https://www.codoid.com'

home_page = Home(driver, base_url).open()

home_page.fill_contact_us_form

driver.quit()

In Conclusion:

We have other page object model packages in Python. We will review them in our subsequent articles. Please feel free to contact us if you face any issues with PyPOM implementation.

Submit a Comment

Your email address will not be published.

Listen to this blog

Page objects are commonly used for testing, but should not make assertions themselves. Their responsibility is to provide access to the state of the underlying page. It’s up to test clients to carry out the assertion logic.

Martin Fowler

In this blog article, you will learn how to implement Page Object Pattern using PyPOM package.

Installation

pip install PyPOM
  

[/code]

Sample Code

from pypom import Page
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(executable_path='driverschromedriver.exe')

class Home(Page):
    _contact_us_locator = (By.ID, 'menu-item-54')

    @property
    def fill_contact_us_form(self):
        self.find_element(*self._contact_us_locator).click()

base_url = 'https://www.codoid.com'

home_page = Home(driver, base_url).open()

home_page.fill_contact_us_form

driver.quit()

In Conclusion:

We have other page object model packages in Python. We will review them in our subsequent articles. Please feel free to contact us if you face any issues with PyPOM implementation.