diff --git a/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py b/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py index c9bc6f22c28478..aa2ad0e2f67a17 100644 --- a/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py +++ b/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py @@ -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("""
foobarBARbaz
@@ -22,8 +27,7 @@ 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 = [ @@ -31,39 +35,77 @@ async def test_find_by_locator(bidi_session, inline, top_context, type, value): "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("""""") +@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("
"), 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"), + ("", "select"), + ("", "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] @@ -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) @@ -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("""
foobarBARbaz
""") await bidi_session.browsing_context.navigate( context=top_context["context"], url=url, wait="complete" @@ -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, @@ -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("
foo
", domain=domain) page_url = inline(f"") @@ -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("
foo
", domain=domain) iframe_url_1 = inline(f"
") @@ -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"
foo
", domain=domain) page_url = inline(f"""
diff --git a/webdriver/tests/classic/get_element_shadow_root/get.py b/webdriver/tests/classic/get_element_shadow_root/get.py index 363652e2fa862f..f033f26977453c 100644 --- a/webdriver/tests/classic/get_element_shadow_root/get.py +++ b/webdriver/tests/classic/get_element_shadow_root/get.py @@ -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", [ - ("

no shadow root

", "div"), - ("", "select"), - ("", "video") -]) -def test_no_shadow_root(session, inline, html, selector): +@pytest.mark.parametrize( + "html, selector", + [ + ("

no shadow root

", "div"), + ("", "select"), + ("", "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")