Skip to main content

Page object model made easy.

Project description

Page object model made easy.

  • Free software: BSD 2-Clause License

Installation

pip install selenium-elements

Documentation

To use the project:

from contextlib import contextmanager

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.expected_conditions import staleness_of
from selenium.webdriver.support.wait import WebDriverWait

from selenium_elements.conditions import clickable
from selenium_elements.elements import PageElement, PageElements, RegionElements
from selenium_elements.page import Page, Region
from selenium_elements.validators import title_matches, url_contains


@contextmanager
def wait_for_page_load(driver, timeout=30):
    old_page = driver.find_element_by_tag_name("html")
    yield
    WebDriverWait(driver, timeout).until(staleness_of(old_page))


class Show(Page):
    path = "/show/{show_slug}/"
    validators = [title_matches("^[a-zA-Z]+ | PBS$"), url_contains("pbs.org/")]

    official_website_btn = PageElement(By.CLASS_NAME, "btn--visit", condition=clickable)

    @property
    def official_website_link(self):
        return self.official_website_btn.get_attribute("href")


class PromoShowRegion(Region):
    title_element = PageElement(By.CLASS_NAME, "carousel--show-strip__image-link")

    def open(self):
        with wait_for_page_load(self.driver):
            self.title_element.click()
        return Show(driver=self.driver, base_url=self.base_url, visit=False)

    def title(self):
        return self.title_element.get_attribute("data-gtm-label")


class Home(Page):
    path = "/"
    load_timeout = 30
    validators = [
        title_matches("^PBS: Public Broadcasting Service$"),
        url_contains("pbs.org/"),
    ]

    promo_show_elements = PageElements(
        By.CLASS_NAME, "show-promo", find_on_page_load=True
    )
    promo_shows = RegionElements(
        region_class=PromoShowRegion, root_element=promo_show_elements
    )


@pytest.fixture
def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()


def test_foo(driver):
    home = Home(driver=driver, base_url="https://www.pbs.org")
    for show in home.promo_shows:
        print(show.title())
    show = home.promo_shows[0].open()
    print(show.official_website_link)
    assert True

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-elements-0.0.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

selenium_elements-0.0.2-py2.py3-none-any.whl (8.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file selenium-elements-0.0.2.tar.gz.

File metadata

  • Download URL: selenium-elements-0.0.2.tar.gz
  • Upload date:
  • Size: 10.7 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.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for selenium-elements-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4f963e83d4487cbc688ebb85ba8895da96745140c3216d83398d0f6a3d4b7fae
MD5 0da345024bf9def6d576bc9a781b633b
BLAKE2b-256 f19d1792d588e18dc01fa945a7033e8ef86d31984cd4b34037b553305c0faaf1

See more details on using hashes here.

File details

Details for the file selenium_elements-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: selenium_elements-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for selenium_elements-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0d042a739580b2d8c3a1bcccadf95d0ee3251e4cece300661f44c50d4ee25bcb
MD5 9fb046aca8023a3dfad7bce9c0351606
BLAKE2b-256 be27e4025953ecf3f26ce025dbbd18e692c3467ddd7ddb6e9ff81ebc580c4976

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