Skip to content

Commit

Permalink
fix: get_by_role include_hidden options (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Mar 16, 2023
1 parent 344c56f commit 890af94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
16 changes: 10 additions & 6 deletions playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ def get_by_text_selector(text: Union[str, Pattern[str]], exact: bool = None) ->
return "internal:text=" + escape_for_text_selector(text, exact=exact)


def bool_to_js_bool(value: bool) -> str:
return "true" if value else "false"


def get_by_role_selector(
role: AriaRole,
checked: bool = None,
Expand All @@ -836,15 +840,15 @@ def get_by_role_selector(
) -> str:
props: List[Tuple[str, str]] = []
if checked is not None:
props.append(("checked", str(checked)))
props.append(("checked", bool_to_js_bool(checked)))
if disabled is not None:
props.append(("disabled", str(disabled)))
props.append(("disabled", bool_to_js_bool(disabled)))
if selected is not None:
props.append(("selected", str(selected)))
props.append(("selected", bool_to_js_bool(selected)))
if expanded is not None:
props.append(("expanded", str(expanded)))
props.append(("expanded", bool_to_js_bool(expanded)))
if includeHidden is not None:
props.append(("include-hidden", str(includeHidden)))
props.append(("include-hidden", bool_to_js_bool(includeHidden)))
if level is not None:
props.append(("level", str(level)))
if name is not None:
Expand All @@ -857,6 +861,6 @@ def get_by_role_selector(
)
)
if pressed is not None:
props.append(("pressed", str(pressed)))
props.append(("pressed", bool_to_js_bool(pressed)))
props_str = "".join([f"[{t[0]}={t[1]}]" for t in props])
return f"internal:role={role}{props_str}"
17 changes: 17 additions & 0 deletions tests/async/test_selectors_get_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,20 @@ async def test_get_by_role_escaping(
)
== []
)


async def test_include_hidden_should_work(
page: Page,
) -> None:
await page.set_content("""<button style="display: none">Hidden</button>""")
assert (
await page.get_by_role("button", name="Hidden").evaluate_all(
"els => els.map(e => e.outerHTML)"
)
== []
)
assert await page.get_by_role(
"button", name="Hidden", include_hidden=True
).evaluate_all("els => els.map(e => e.outerHTML)") == [
"""<button style="display: none">Hidden</button>""",
]

0 comments on commit 890af94

Please sign in to comment.