Skip to main content

Pomcorn

GitHub last commit GitHub Workflow Status (with event) PyPI PyPI - Status PyPI - Python Version PyPI - License PyPI - Downloads Ruff prek

Check out our other open-source projects

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. 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: https://saritasa-nest.github.io/pomcorn/latest/.

Usage

Install pomcorn using installation guide.

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.

Release files for pomcorn 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pomcorn 0.11.0
File Size Uploaded
pomcorn-0.11.0.tar.gz 406.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pomcorn 0.11.0
File Interpreter ABI Platform
pomcorn-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 430.5 kB

Release files / pomcorn-0.11.0.tar.gz

Download URL pomcorn-0.11.0.tar.gz
Size 406.9 kB
Tags Source
SHA-256 checksum
How to use checksums
056e2a0b18eafd1972e98524362383ed49736537e6d6842c92b18ed36970c435
BLAKE2b-256 checksum
How to use checksums
ddbd563f366af47dbde5867cc7c8268dccb08a7fa66372d58c4563fbe73889ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pomcorn-0.11.0-py3-none-any.whl

Download URL pomcorn-0.11.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
864d4cdc8980765adad3c4fef39b0b62d3c03ce4541df89c73f929f67bbfa0b6
BLAKE2b-256 checksum
How to use checksums
141f1236c89592443f3b6b954fef35d66c86de360151b7d5f0ca3d7c2d1860b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page