Page Object Pattern in Python - Codoid
Select Page
Codoid Blog

Page Object Pattern in Python

Irrespective of the business that your client is in, marketing is an integral part of their operations. In fact, in this day and age of social.

Page Object Pattern in Python helps to reduce code duplication and enhances automation testing maintenance. Using a page object class, you can represent a web page or mobile app screen of your software under test (SUT).

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()
[/code]

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.

Written By

Submit a Comment

Your email address will not be published. Required fields are marked *


Page Object Pattern in Python helps to reduce code duplication and enhances automation testing maintenance. Using a page object class, you can represent a web page or mobile app screen of your software under test (SUT).

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()
[/code]

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.