Skip to main content

selenium-page-factory

Python library provides page factory approach to implement page object model in selenium

Project Page

https://github.com/NayakwadiS/selenium-page-factory

Project Documentation

https://selenium-page-factory.readthedocs.io

Introduction

  • A Page Factory is one way of implementing a Page Object Model. In order to support the Page Object pattern.
  • As in Java we are using @findBy, here we are declaring all web element in dictionary. Dictionary keys become WebElement / class member variable with having all extended WebElement methods.

Main Features

  • Initialise all the webElements declared in Point at a time.
  • All WebElements methods are re-define to add extra features eg- click method extended to have explicit wait for element to be clickable.
  • Cent percent unittest coverage.

Installation

  pip install selenium-page-factory

Pre-Requisite

Every Page in Page Object Model should have WebDriver object as class member as shown below

class PageClass(PageFactory):

    def __init__(self,driver):
        self.driver = driver

WebElements Methods

  • set_text
  • get_text
  • clear_text
  • click_button
  • get_list_item_count
  • select_element_by_text
  • select_element_by_index
  • select_element_by_value
  • get_all_list_item
  • get_list_selected_item
  • hover
  • is_Checked
  • getAttribute
  • element_to_be_clickable
  • invisibility_of_element_located
  • visibility_of_element_located

Note: Every WebElement will be created after verifying it's Presence and visibility on Page at Run-Time.

Examples

Python - Unittest

from seleniumpagefactory.Pagefactory import PageFactory
import unittest
from selenium import webdriver

class LoginPage(PageFactory):

    def __init__(self,driver):
        # It is necessary to to initialise driver as page class member to implement Page Factory
        self.driver = driver

    # define locators dictionary where key name will became WebElement using PageFactory
    locators = {
        "edtUserName": ('ID', 'user_login'),
        "edtPassword": ('NAME', 'pwd'),
        "btnSignIn": ('XPATH', '//input[@value="Log In"]')
    }

    def login(self):
        # set_text(), click_button() methods are extended methods in PageFactory
        self.edtUserName.set_text("opensourcecms")               # edtUserName become class variable using PageFactory
        self.edtPassword.set_text("opensourcecms")
        self.btnSignIn.click_button()


class LoginTest(unittest.TestCase):

    def test_Login(self):
        driver = webdriver.Chrome()
        driver.get("https://s1.demo.opensourcecms.com/wordpress/wp-login.php")

        pglogin = LoginPage(driver)
        pglogin.login()

if __name__ == "__main__":
     unittest.main()

Python - Pytest

Inside test_Login.py

import pytest
from selenium import webdriver
from seleniumpagefactory.Pagefactory import PageFactory

def test_Login():
    driver = webdriver.Chrome("")
    driver.get("https://s1.demo.opensourcecms.com/wordpress/wp-login.php")

    pglogin = LoginPage(driver)
    pglogin.login()

class LoginPage(PageFactory):

    def __init__(self,driver):
        # It is necessary to to initialise driver as page class member to implement Page Factory
        self.driver = driver

    # define locators dictionary where key name will became WebElement using PageFactory
    locators = {
        "edtUserName": ('ID', 'user_login'),
        "edtPassword": ('NAME', 'pwd'),
        "btnSignIn": ('XPATH', '//input[@value="Log In"]')
    }

    def login(self):
        # set_text(), click_button() methods are extended methods in PageFactory
        self.edtUserName.set_text("opensourcecms")               # edtUserName become class variable using PageFactory
        self.edtPassword.set_text("opensourcecms")
        self.btnSignIn.click_button()

Metadata

Release files for selenium-page-factory 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for selenium-page-factory 1.5
File Size Uploaded Provenance Actions
selenium-page-factory-1.5.tar.gz 4.9 kB Without provenance Details for selenium-page-factory-1.5.tar.gz

Release files / selenium-page-factory-1.5.tar.gz

Download URL selenium-page-factory-1.5.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a2f9b95b7d389ecf2ba22380557ec64f6d75a3e8674dbac1db0314a2e6235db9
BLAKE2b-256 checksum
How to use checksums
b4e55d792b4ec1fa8440d063ba5256c78a9005c99d843b10d40cebe9300fad3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.2

Security for selenium-page-factory 1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page