Skip to main content

Page Object constructor for UI automation

Project description

Web-Bricks

Install

python3 -m pip install web-bricks

Usage

from web_bricks import WebBricksConfig, web_resolver, WebBrick, many, checkable
from typing import List


# at PageObject:

# просто какая то функция композиции локаторов
def make_locator(val):
    return {'by': 'css', 'value': val}


class WebElement(WebBrick):
    def click(self):
        return checkable(self).click().apply()
    
    def get_text(self):
        return checkable(self).text  # driver method
    
    def text(self):
        return self.get_text().apply()


class SubElement(WebElement):
    pass


class MoreSubElement(WebElement):
    pass


class RootPage(WebElement):
    @property
    def sub_page(self) -> SubElement:
        locator = make_locator('some')
        return SubElement(self, locator)

    @property
    def sub_elements(self) -> List[MoreSubElement]:
        return many(MoreSubElement(self, locator=make_locator('another')))


# at TearUp:

selenium_resolver_config = WebBricksConfig(
    resolver=web_resolver(waiter=SeleniumWaiter, timeout=10)
)
selenium_driver = webdriver.Remote(...)
root_page = RootPage(selenium_driver, locator=make_locator(':root'), config=selenium_resolver_config)

# at Test:
root_page.sub_page.resolved_element.click()
root_page.sub_elements[1].resolved_element.click()
root_page.sub_elements[1].resolved_element.text

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

web-bricks-0.1.1.tar.gz (11.3 kB view hashes)

Uploaded Source

Built Distribution

web_bricks-0.1.1-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

Supported by

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