Skip to main content

Page Object constructor for UI automation

Project description

Web-Bricks

Install

python3 -m pip install web-bricks

Usage

Example page:

<html>
  <body>
    <div data-n="single-element-on-root-page">
    <div data-n="block-on-root-page">
      <ul>
        <li data-n="element-of-list">Cheburechka</li>
        <li data-n="element-of-list">Some value</li>
        <li data-n="element-of-list">Some Another Value</li>
     </ul>
  </body>
</html>

WebBrick

Make Driver Actions

# PlayWright
from web_bricks import WebBrick
from playwright.async_api import ElementHandle


class WebElement(WebBrick):
    async def element(self) -> ElementHandle:
        return await self.driver.wait_for_selector(f'xpath={self.full_locator_str}')
    
    async def tap(self):
        return await self.element.tap()
    
    async def is_visible(self):
        try:
            await self.driver.wait_for_selector(f'xpath={self.full_locator_str}', state='visible')
        except TimeoutError as e:
            return False
        return True
    
    @property
    async def inner_text(self):
        return await self.element.inner_text('value')

Make Page Object Tree Interface

from web_bricks import many
from typing import List

class RootPageSingleElement(WebElement):
    LOCATOR = '//*[@data-n="single-element-on-root-page"]'

class RootPageListElements(WebElement):
    LOCATOR = '//*[@data-n="element-of-list"]'
    
class RootPageBlock(WebElement):
    LOCATOR = '//*[@data-n="block-on-root-page"]'
    
    @property
    def element_of_list(self) -> List[RootPageListElements]:
        return many(RootPageListElements(self))   
    
class RootPage(WebElement):
    LOCATOR = '/*'
    
    @property
    def single_element(self) -> RootPageSingleElement:
        return RootPageSingleElement(self)   
    
    @property
    def block(self) -> RootPageBlock:
        return RootPageBlock(self)

Do the things

from web_brick import str_xpath_locator_extractor

with async_playwright() as playwright:
    browser = playwright.chromium.lunch()
    page = browser.new_page() 
    
    # treat LOCATOR as xpath string
    app = RootPage(page, config=WebBricksConfig(locator_repr_extractor=xpath_str_locator_extractor)
    
    # Interact with PO
    var_zero_elem_value = await app.block.element_of_list[0].inner_text
    
    await app.single_element.tap()
    assert await app.block.is_visible()
    assert app.block.element_of_list[0].is_visible()
    
    assert app.block.element_of_list[0].inner_text == 'SomeValue'
    assert app.block.element_of_list[3].inner_text == var_zero_elem_value

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.3.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

web_bricks-0.1.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file web-bricks-0.1.3.tar.gz.

File metadata

  • Download URL: web-bricks-0.1.3.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for web-bricks-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b9df618e51d7707002e514db09bd41e11829d40c5e3134cb594d4aac33608db8
MD5 2bb00264fa925f0dfb94f5da365ea5ac
BLAKE2b-256 4a0869829684a973ca73c2adf143977317c2cfaebde89c69eb4a9b243a8528dc

See more details on using hashes here.

File details

Details for the file web_bricks-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: web_bricks-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for web_bricks-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4a555111f58857b0077948f474eda8ba972a23cbe6c5712a6d999e75771f9979
MD5 14213607f87dfdfb713fc5185a8df755
BLAKE2b-256 a2c24adfc342e8b8e784868a4eb2487019194faefbfec09a6887e989b465baf6

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