Skip to content
Open
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
101 changes: 71 additions & 30 deletions webdriver/tests/bidi/browsing_context/locate_nodes/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

from ... import any_string, recursive_compare

pytestmark = pytest.mark.asyncio

@pytest.mark.parametrize("type,value", [
("css", "div"),
("xpath", "//div"),
("innerText", "foobarBARbaz"),
("accessibility", {"role": "banner"}),
("accessibility", {"name": "foo"}),
("accessibility", {"role": "banner", "name": "foo"}),
])
@pytest.mark.asyncio

@pytest.mark.parametrize(
"type,value",
[
("css", "div"),
("xpath", "//div"),
("innerText", "foobarBARbaz"),
("accessibility", {"role": "banner"}),
("accessibility", {"name": "foo"}),
("accessibility", {"role": "banner", "name": "foo"}),
],
ids=["css", "xpath", "innerText", "a11y-role", "a11y-name", "a11y-both"],
)
async def test_find_by_locator(bidi_session, inline, top_context, type, value):
url = inline("""
<div data-class="one" role="banner" aria-label="foo">foobarBARbaz</div>
Expand All @@ -22,48 +27,85 @@ async def test_find_by_locator(bidi_session, inline, top_context, type, value):
)

result = await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": type, "value": value }
context=top_context["context"], locator={"type": type, "value": value}
)

expected = [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"attributes": {"data-class": "one"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
},
},
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"two"},
"attributes": {"data-class": "two"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
}
},
},
]

recursive_compare(expected, result["nodes"])


@pytest.mark.asyncio
async def test_find_by_locator_select(bidi_session, inline, top_context):
url = inline("""<select></select>""")
@pytest.mark.parametrize("value", [":root", "html"])
async def test_find_root_element_by_css_locator(
bidi_session, inline, top_context, value
):
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=inline("<div>"), wait="complete"
)

result = await bidi_session.browsing_context.locate_nodes(
context=top_context["context"], locator={"type": "css", "value": value}
)

expected = [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {},
"childNodeCount": 2,
"localName": "html",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
},
]

recursive_compare(expected, result["nodes"])


@pytest.mark.parametrize(
"html, selector",
[
("<div></div>", "div"),
("<select></select>", "select"),
("<video></video>", "video"),
],
ids=["div", "select", "video"],
)
async def test_no_user_agent_shadow_root(
bidi_session, inline, top_context, html, selector
):
url = inline(html)
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
)

result = await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={ "type": "css", "value": "select" }
context=top_context["context"], locator={"type": "css", "value": selector}
)

node_result = result["nodes"][0]
Expand All @@ -73,13 +115,13 @@ async def test_find_by_locator_select(bidi_session, inline, top_context):
"value": {
"attributes": {},
"childNodeCount": 0,
"localName": "select",
"localName": selector,
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
# Make sure user-agent shadow roots are not leaked by locateNodes
# (eg Firefox uses shadow dom to implement the select widget).
"shadowRoot": None,
}
},
}
recursive_compare(expected, node_result)

Expand Down Expand Up @@ -179,8 +221,9 @@ async def test_find_by_locator_select(bidi_session, inline, top_context):
"ignore_case_true_partial_match_max_depth_two",
"ignore_case_false_partial_match_max_depth_two",
])
@pytest.mark.asyncio
async def test_find_by_inner_text(bidi_session, inline, top_context, locator, expected_nodes_values):
async def test_find_by_inner_text(
bidi_session, inline, top_context, locator, expected_nodes_values
):
url = inline("""<div>foo<span><strong>bar</strong></span><span>BAR</span>baz</div>""")
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
Expand Down Expand Up @@ -237,7 +280,6 @@ async def test_find_by_inner_text(bidi_session, inline, top_context, locator, ex
),
],
)
@pytest.mark.asyncio
async def test_locate_by_accessibility_attributes(
bidi_session,
inline,
Expand Down Expand Up @@ -269,7 +311,6 @@ async def test_locate_by_accessibility_attributes(


@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
@pytest.mark.asyncio
async def test_locate_by_context(bidi_session, inline, top_context, domain):
iframe_url_1 = inline("<div>foo</div>", domain=domain)
page_url = inline(f"<iframe id='target' src='{iframe_url_1}'></iframe>")
Expand Down Expand Up @@ -304,7 +345,6 @@ async def test_locate_by_context(bidi_session, inline, top_context, domain):


@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
@pytest.mark.asyncio
async def test_locate_by_context_in_iframe(bidi_session, inline, top_context, domain):
iframe_url_2 = inline("<div>foo</div>", domain=domain)
iframe_url_1 = inline(f"<div><iframe id='target' src='{iframe_url_2}'></iframe></div>")
Expand Down Expand Up @@ -342,8 +382,9 @@ async def test_locate_by_context_in_iframe(bidi_session, inline, top_context, do

@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
@pytest.mark.parametrize("mode", ["open", "closed"])
@pytest.mark.asyncio
async def test_locate_by_context_in_shadow_dom(bidi_session, inline, top_context, domain, mode):
async def test_locate_by_context_in_shadow_dom(
bidi_session, inline, top_context, domain, mode
):
iframe_url_1 = inline(f"<div>foo</div>", domain=domain)
page_url = inline(f"""
<div id="host"></div>
Expand Down
20 changes: 14 additions & 6 deletions webdriver/tests/classic/get_element_shadow_root/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,21 @@ def test_get_shadow_root(session, get_test_page):
assert_same_element(session, host_element, expected_host)


@pytest.mark.parametrize("html, selector", [
("<div><p>no shadow root</p></div>", "div"),
("<select></select>", "select"),
("<video></video>", "video")
])
def test_no_shadow_root(session, inline, html, selector):
@pytest.mark.parametrize(
"html, selector",
[
("<div><p>no shadow root</p></div>", "div"),
("<select></select>", "select"),
("<video></video>", "video"),
],
ids=["div", "select", "video"],
)
def test_no_user_agent_shadow_root(session, inline, html, selector):
session.url = inline(html)

element = session.find.css(selector, all=False)

# Make sure user-agent shadow roots are not leaked by get shadow root
# (eg Firefox uses shadow dom to implement the select widget).
response = get_shadow_root(session, element.id)
assert_error(response, "no such shadow root")