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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| web-bricks-0.1.3.tar.gz | 12.7 kB | Without provenance | Details for web-bricks-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| web_bricks-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for web_bricks-0.1.3-py3-none-any.whl |
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
|
Security for web-bricks 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.