Skip to main content

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

Metadata

Release files for web-bricks 0.1.3

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

Source distribution (sdist)

Source distribution for web-bricks 0.1.3
File Size Uploaded
web-bricks-0.1.3.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for web-bricks 0.1.3
File Interpreter ABI Platform
web_bricks-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 27.4 kB

Release files / web-bricks-0.1.3.tar.gz

Download URL web-bricks-0.1.3.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b9df618e51d7707002e514db09bd41e11829d40c5e3134cb594d4aac33608db8
BLAKE2b-256 checksum
How to use checksums
4a0869829684a973ca73c2adf143977317c2cfaebde89c69eb4a9b243a8528dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / web_bricks-0.1.3-py3-none-any.whl

Download URL web_bricks-0.1.3-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a555111f58857b0077948f474eda8ba972a23cbe6c5712a6d999e75771f9979
BLAKE2b-256 checksum
How to use checksums
a2c24adfc342e8b8e784868a4eb2487019194faefbfec09a6887e989b465baf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

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