Skip to main content

Base implementation of Page Object Model

Project description

Pomcorn

GitHub Workflow Status (with event) PyPI PyPI - Status PyPI - Python Version PyPI - License PyPI - Downloads Code style: black Imports: isort

Pomcorn, or Page Object Model corn, is a Python package that contains base classes to create systems based on Selenium framework and Page Object Model pattern. You can read more about this pattern here. The package can be used to create autotesting systems, parsing scripts and anything that requires interaction with the browser.

The package includes next base classes to create Page Object Model (POM) pages:

  classDiagram
    WebView <|-- Component
    WebView <|-- Page
    Component <|-- ListComponent
    Component .. Locator
    Page .. Component

    class WebView{
        -webdriver: Webdriver
    }
    class Page{
        +wait_until_loaded()
        +open()
    }
    class Component{
        -page: Page
        -base_locator: Locator
        + wait_until_visible()
    }
    class ListComponent{
        -item_locator: Locator
        +count()
        +all()
        +get_item_by_text()
    }
    class Locator{
      -query: String
    }

It also includes classes to locate elements on the web page and a number of additional waiting conditions.

Installation

You can install it by pip:

  pip install pomcorn

Or poetry:

  poetry add pomcorn

Documentation

Link to the documentation: http://pomcorn.rtfd.io/.

Usage

You need to install pomcorn and Chrome webdriver.

Below is the code that opens PyPI.org, searches for packages by name and prints names of found packages to the terminal. The script contains all base classes contained in pomcorn: Page, Component, ListComponent and Element.

  from typing import Self

  from selenium.webdriver import Chrome
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.remote.webdriver import WebDriver

  from pomcorn import Component, Element, ListComponent, Page, locators


  # Prepare base page
  class PyPIPage(Page):

      APP_ROOT = "https://pypi.org"

      search = Element(locators.IdLocator("search"))

      def check_page_is_loaded(self) -> bool:
          return self.init_element(locators.TagNameLocator("main")).is_displayed


  # Prepare components
  Package = Component[PyPIPage]


  class PackageList(ListComponent[Package, PyPIPage]):

      relative_item_locator = locators.ClassLocator("snippet__name")

      @property
      def names(self) -> list[str]:
          return [package.body.get_text() for package in self.all]


  # Prepare search page
  class SearchPage(PyPIPage):

      @classmethod
      def open(cls, webdriver: WebDriver, **kwargs) -> Self:
          pypi_page = super().open(webdriver, **kwargs)
          # Specific logic for PyPI for an open search page
          pypi_page.search.fill("")
          pypi_page.search.send_keys(Keys.ENTER)
          return cls(webdriver, **kwargs)

      @property
      def results(self) -> PackageList:
          return PackageList(
              page=self,
              base_locator=locators.PropertyLocator(
                  prop="aria-label",
                  value="Search results",
              ),
          )

      def find(self, query: str) -> PackageList:
          self.search.fill(query)
          self.search.send_keys(Keys.ENTER)
          return self.results


  search_page = SearchPage.open(webdriver=Chrome())
  print(search_page.find("saritasa").names)
  search_page.webdriver.close()

For more information about package classes, you can read in Object Hierarchy and Developer Interface.

Also you can try our demo autotests project.

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

pomcorn-0.8.1.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pomcorn-0.8.1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file pomcorn-0.8.1.tar.gz.

File metadata

  • Download URL: pomcorn-0.8.1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.7 Linux/5.13.19-2-MANJARO

File hashes

Hashes for pomcorn-0.8.1.tar.gz
Algorithm Hash digest
SHA256 da9f699dadddc2a20874b049745d7d0e7235e3e47a64f621057d7495de6b225c
MD5 a65ce0cf8c20a3cd3ab2cc8e460f999c
BLAKE2b-256 39bc2519d1b49a1e449e6555cc372b90f58c9ca3970a544ece81ac106bc2ab5d

See more details on using hashes here.

File details

Details for the file pomcorn-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: pomcorn-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.7 Linux/5.13.19-2-MANJARO

File hashes

Hashes for pomcorn-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d16c0402a13d5702099dcdf9bc705a70ebcb465d6fae391efc99407647d29cc8
MD5 3052727041e3f1a6552b0741d020befc
BLAKE2b-256 bca0fd70f3eb68576d93775a82762d9fd895ddf8aa008ed16a32d8f32b85232e

See more details on using hashes here.

Supported by

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