Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ concurrency:
on:
push:
branches:
- playwright
- main
pull_request:
types: ["opened", "synchronize", "reopened"]
schedule:
Expand Down
22 changes: 22 additions & 0 deletions src/widgetastic/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,28 @@ def set_attribute(self, attr: str, value: str, *args, **kwargs) -> None:
)
self.logger.debug("set attribute for %r => %r=%r", args, attr, value)

def value_of_css_property(
self, locator: LocatorAlias, property: str, *args, **kwargs
) -> Optional[str]:
"""Retrieves the value of specified computed style property of an element in the current browsing context.

Args:
locator: Element locator to get css property
property: CSS property to get the value of
*args: Additional arguments passed to element() method
**kwargs: Additional keyword arguments passed to element() method

Returns:
Value of css property.
"""
self.logger.debug(
"Retrieving value of css property '%s' for locator: %r", property, locator
)
el = self.element(locator, *args, **kwargs)
return el.evaluate(
f"element => window.getComputedStyle(element).getPropertyValue('{property}')"
)

# ================== ELEMENT GEOMETRY & VISUAL PROPERTIES ==================
def size_of(self, *args, **kwargs) -> Size:
"""Returns element's size as a tuple of width/height.
Expand Down
2 changes: 1 addition & 1 deletion testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def playwright_browser_instance(
def browser_context(playwright_browser_instance: PlaywrightBrowser) -> BrowserContext:
"""Creates a browser context for the entire test session."""
context = playwright_browser_instance.new_context(
viewport={"width": 1280, "height": 720},
viewport={"width": 1920, "height": 1080},
)
yield context
context.close()
Expand Down
8 changes: 8 additions & 0 deletions testing/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ def test_set_attribute(browser):
assert browser.get_attribute("foo", "#invisible") == "bar"


def test_value_of_css_property(browser):
assert browser.value_of_css_property(locator="#test-image-full", property="margin") == "5px"
assert (
browser.value_of_css_property(locator="#test-image-full", property="border-color")
== "rgb(221, 221, 221)"
)


# ================== ELEMENT GEOMETRY & VISUAL PROPERTIES TESTS ==================


Expand Down