Skip to main content

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

Project description

Project Page

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

selenium-page-factory

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

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.
  • Cent percent unittest coverage.

Installation

pip install:

> pip install selenium-page-factory

Examples

  1. 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()
  1. 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()

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium-page-factory-1.3.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file selenium-page-factory-1.3.tar.gz.

File metadata

  • Download URL: selenium-page-factory-1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for selenium-page-factory-1.3.tar.gz
Algorithm Hash digest
SHA256 2d934fefc68b27783af4db77bce1e4aff6eff260dacf5d02f611d836f614a57e
MD5 31d45e548df3dc634baf006621343c26
BLAKE2b-256 5702c0ddc31c8fa71458675aea265bc53edcda7cf4a742ec87dc6d9e5d34a3dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page