Skip to main content

PySelPOM is a Page Object Model selenium based framework for humans.

Project description

Github-flavored Markdown

PySelPOM

PySelPOM is a Page Object Model selenium based framework for humans. It allows you to write your own web test with no need to look under the framework hood in most cases.

Installation

For most users, the recommended method to install is via pip:

pip install pyselpom

or from source:

python setup.py install

Conftest content

import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


def pytest_addoption(parser):
    parser.addoption('--language', action='store', default='en', help='Specify language param.')
    parser.addoption('--browser_name', action='store', default='chrome', help='Choose browser: chrome or firefox')


@pytest.fixture
def driver(request) -> webdriver:
    user_language = request.config.getoption('language')
    browser_name = request.config.getoption('browser_name')

    if browser_name == 'chrome':
        print('\nStart chrome browser for test...')
        options = Options()
        # noinspection PyTypeChecker
        options.add_experimental_option('prefs', {'intl.accept_languages': user_language})
        browser = webdriver.Chrome(options=options)
    elif browser_name == 'firefox':
        print('\nStart firefox browser for test...')
        fp = webdriver.FirefoxProfile()
        fp.set_preference('intl.accept_languages', user_language)
        browser = webdriver.Firefox(firefox_profile=fp)
    else:
        raise pytest.UsageError('--browser_name should be chrome or firefox')

    yield browser

    browser.quit()

Page example

from pyselpom import BasePage


class MainPage(BasePage):
    URL_PATTERN = 'https://google.com/'


class LoginPage(BasePage):
    link = 'https://google.com/login/'

    def should_be_login_page(self):
        self.should_be_login_url()
        self.should_be_login_form()
        self.should_be_register_form()

    def should_be_login_url(self):
        assert 'login' in self.browser.current_url

    def should_be_login_form(self):
        assert self.is_element_present(*LoginPageLocators.LOGIN_FORM), 'Login form does not exist.'

    def should_be_register_form(self):
        assert self.is_element_present(*LoginPageLocators.REGISTER_FORM), 'Register form does not exist.'

    def register_new_user(self, email, password):
        self.browser.find_element(*LoginPageLocators.REGISTER_MAIL).send_keys(email)
        self.browser.find_element(*LoginPageLocators.REGISTER_PASSWORD).send_keys(password)
        self.browser.find_element(*LoginPageLocators.REGISTER_PASSWORD_CONFIRM).send_keys(password)
        self.browser.find_element(*LoginPageLocators.REGISTER).click()

Locators

from selenium.webdriver.common.by import By


class LoginPageLocators:
    LOGIN_FORM = (By.ID, 'login_form')
    REGISTER_FORM = (By.ID, 'register_form')
    REGISTER_MAIL = (By.NAME, 'registration-email')
    REGISTER_PASSWORD = (By.NAME, 'registration-password1')
    REGISTER_PASSWORD_CONFIRM = (By.NAME, 'registration-password2')
    REGISTER = (By.NAME, 'registration_submit')

Test example

import pytest

from .pages.login_page import LoginPage
from .pages.main_page import MainPage


@pytest.mark.login_guest
class TestLoginFromMainPage:
    def test_guest_can_go_to_login_page(self, browser):
        page = MainPage(browser, MainPage.link)
        page.open()
        page.go_to_login_page()
        login_page = LoginPage(browser, browser.current_url)
        login_page.should_be_login_page()

Changelog

1.2.3 (2-03-2022)

  • .is_<methods> returns bool now

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

pyselpom-1.2.3.tar.gz (9.1 kB view hashes)

Uploaded source

Built Distribution

pyselpom-1.2.3-py3-none-any.whl (12.5 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page