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_ 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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pyselpom-1.2.3.tar.gz.

File metadata

  • Download URL: pyselpom-1.2.3.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0

File hashes

Hashes for pyselpom-1.2.3.tar.gz
Algorithm Hash digest
SHA256 9659e0de54b5ff97ea08a162247b42ebc147c0c98fd3b34516c6a306ea733e2d
MD5 53407cc9b703735801c3f3a38938bdf1
BLAKE2b-256 cd32f2cd7c4dae5684d0782c32442ac42ef894d98148622dd6f07d38d4ae4438

See more details on using hashes here.

File details

Details for the file pyselpom-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: pyselpom-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0

File hashes

Hashes for pyselpom-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e97e2afb4c625d1bfac9d28a3d9ea37060e8b2844a967251c8553ce2a6b4736
MD5 d97d56d0f801e6240b12a98ee1e6d954
BLAKE2b-256 f8e7460b51ad757d5058d5f78e4fc259e235e7336ce1029062ffe562223c45eb

See more details on using hashes here.

Supported by

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