Base implementation of Page Object Model
Project description
Pomcorn
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]):
item_class = Package
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pomcorn-0.8.0.tar.gz
.
File metadata
- Download URL: pomcorn-0.8.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.5-1-MANJARO
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9945277d710bbebabea45fd0c0ccbcb39f2d40b932e080d80b7020579a8a7024 |
|
MD5 | 328b2ecc768bd390036b5a99cfd47ba3 |
|
BLAKE2b-256 | d41435a7387a6dec532f9bd76413e1181b9698a89cb7c6c69c65bac0927b2399 |
File details
Details for the file pomcorn-0.8.0-py3-none-any.whl
.
File metadata
- Download URL: pomcorn-0.8.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.5-1-MANJARO
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f726e4b851bc9047123f562b57080781fb9f986be5616fd4be262ef3048f2464 |
|
MD5 | eca0d206d5de14ec264599feec4db665 |
|
BLAKE2b-256 | 6cedb3aaf855c091569169c55b485fdcca4ff4d18c766825ddfad8ab5ba5a076 |