Git Product home page Git Product logo

pomcorn's Introduction

Pomcorn

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:

Class diagram

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, ComponentWithBaseLocator, 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 ComponentWithBaseLocator, Element, ListComponent, Page, locators


# Prepare base page
class PyPIPage(Page):

    APP_ROOT = "https://pypi.org"

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

    @property
    def search(self) -> Element[locators.XPathLocator]:
        return self.init_element(locators.IdLocator("search"))


# Prepare components
Package = ComponentWithBaseLocator[PyPIPage]


class PackageList(ListComponent[Package, PyPIPage]):

    item_class = Package

    @property
    def base_item_locator(self) -> locators.XPathLocator:
        return self.base_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)

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

Also you can try our demo autotests project.

pomcorn's People

Contributors

dependabot[bot] avatar m1troll avatar terraform-cicd-app[bot] avatar thesuperiorstanislav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pomcorn's Issues

Add ability to define `base_locator` as class attribute

Could you please extend ComponentWithBaseLocator and provide ability to define base_locator as class attribute like

class Header(ComponentWithBaseLocator):
    base_locator = locators.ClassLocator("navigation-bar")

	def open_index_page(self):
        ...

Currently it's required to override __init__ method to do this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.