From 6dea733a21aaaddad68e45aa36141931293a3c68 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 13 Jan 2025 10:50:25 +0100 Subject: [PATCH 1/4] [wdspec] add invalid context test --- .../browsing_context/locate_nodes/invalid.py | 23 +++++++++- .../browsing_context/locate_nodes/locator.py | 43 +++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py b/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py index 2eb2c3d806caf4..05f9bf6ebb386d 100644 --- a/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py +++ b/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py @@ -76,7 +76,7 @@ async def test_params_locator_accessability_value_invalid_type( ("xpath", ""), ("innerText", ""), ("accessibility", {}), - ("context", {}) + ("context", {"context": ""}) ]) async def test_params_locator_value_invalid_value(bidi_session, inline, top_context, type, value): await navigate_to_page(bidi_session, inline, top_context) @@ -218,3 +218,24 @@ async def test_params_start_nodes_dom_node_not_element( locator={"type": "css", "value": "div"}, start_nodes=[remote_reference], ) + + +@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) +@pytest.mark.asyncio +async def test_locate_by_context_invalid_context(bidi_session, inline, top_context, domain): + iframe_url_2 = inline("
foo
", domain=domain) + iframe_url_1 = inline(f"
", domain=domain) + page_url = inline(f"") + + await bidi_session.browsing_context.navigate( + context=top_context["context"], url=page_url, wait="complete" + ) + + contexts = await bidi_session.browsing_context.get_tree(root=top_context["context"]) + iframe2_context = contexts[0]["children"][0]["children"][0] + + with pytest.raises(error.InvalidArgumentException): + await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], + locator={"type": "context", "value": { "context": iframe2_context["context"] }} + ) diff --git a/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py b/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py index 6cbe799958a8ff..07885057dca4ce 100644 --- a/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py +++ b/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py @@ -241,8 +241,8 @@ 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"") + iframe_url_1 = inline("
foo
", domain=domain) + page_url = inline(f"") await bidi_session.browsing_context.navigate( context=top_context["context"], url=page_url, wait="complete" @@ -261,7 +261,44 @@ async def test_locate_by_context(bidi_session, inline, top_context, domain): "type": "node", "sharedId": any_string, "value": { - "attributes": {"src": any_string}, + "attributes": {"src": any_string, "id": "target"}, + "childNodeCount": 0, + "localName": "iframe", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + } + } + ] + + recursive_compare(expected, result["nodes"]) + + +@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"
") + page_url = inline(f"") + + await bidi_session.browsing_context.navigate( + context=top_context["context"], url=page_url, wait="complete" + ) + + contexts = await bidi_session.browsing_context.get_tree(root=top_context["context"]) + iframe1_context = contexts[0]["children"][0] + iframe2_context = contexts[0]["children"][0]["children"][0] + + result = await bidi_session.browsing_context.locate_nodes( + context=iframe1_context["context"], + locator={"type": "context", "value": { "context": iframe2_context["context"] }} + ) + + expected = [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"src": any_string, "id": "target"}, "childNodeCount": 0, "localName": "iframe", "namespaceURI": "http://www.w3.org/1999/xhtml", From fa5ffed237a2445821da0ead6923ff1a88330b15 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 13 Jan 2025 15:50:31 +0100 Subject: [PATCH 2/4] add shadow DOM tests --- .../browsing_context/locate_nodes/locator.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py b/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py index 07885057dca4ce..117a2d10fa996d 100644 --- a/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py +++ b/webdriver/tests/bidi/browsing_context/locate_nodes/locator.py @@ -308,3 +308,48 @@ async def test_locate_by_context_in_iframe(bidi_session, inline, top_context, do ] recursive_compare(expected, result["nodes"]) + + +@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): + iframe_url_1 = inline(f"
foo
", domain=domain) + page_url = inline(f""" +
+ + """) + + await bidi_session.browsing_context.navigate( + context=top_context["context"], url=page_url, wait="complete" + ) + + contexts = await bidi_session.browsing_context.get_tree(root=top_context["context"]) + iframe1_context = contexts[0]["children"][0] + + result = await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], + locator={"type": "context", "value": { "context": iframe1_context["context"] }} + ) + + expected = [ + { + "type": "node", + "sharedId": any_string, + "value": { + "attributes": {"src": any_string, "id": "target"}, + "childNodeCount": 0, + "localName": "iframe", + "namespaceURI": "http://www.w3.org/1999/xhtml", + "nodeType": 1, + } + } + ] + + recursive_compare(expected, result["nodes"]) From 21cb81a5f34c06fc2b29fb308b125e6889abe9b5 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Tue, 14 Jan 2025 13:56:05 +0100 Subject: [PATCH 3/4] Extend invalid values tests --- .../browsing_context/locate_nodes/invalid.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py b/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py index 05f9bf6ebb386d..fdb7e854fd1548 100644 --- a/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py +++ b/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py @@ -71,6 +71,45 @@ async def test_params_locator_accessability_value_invalid_type( ) +@pytest.mark.parametrize("value", [None, False, 42, "", []]) +async def test_params_locator_context_invalid_type(bidi_session, inline, + top_context, value): + await navigate_to_page(bidi_session, inline, top_context) + + with pytest.raises(error.InvalidArgumentException): + await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], + locator={"type": "context", "value": value} + ) + + +@pytest.mark.parametrize("value", [None, False, 42, {}, []]) +async def test_params_locator_context_value_invalid_type(bidi_session, inline, + top_context, value): + await navigate_to_page(bidi_session, inline, top_context) + + with pytest.raises(error.InvalidArgumentException): + await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], + locator={"type": "context", "value": { + "context": value + }} + ) + + +@pytest.mark.parametrize("value", ["non_exiting_context"]) +async def test_params_locator_context_value_invalid_context(bidi_session, + inline, top_context, value): + await navigate_to_page(bidi_session, inline, top_context) + + with pytest.raises(error.NoSuchFrameException): + await bidi_session.browsing_context.locate_nodes( + context=top_context["context"], + locator={"type": "context", "value": { + "context": value + }} + ) + @pytest.mark.parametrize("type,value", [ ("css", "a*b"), ("xpath", ""), From 17868f695a64dd13da99612f432ad300a0652f45 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Tue, 14 Jan 2025 14:08:44 +0100 Subject: [PATCH 4/4] Use `iframe` fixture --- .../tests/bidi/browsing_context/locate_nodes/invalid.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py b/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py index fdb7e854fd1548..c1c545e9bb9967 100644 --- a/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py +++ b/webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py @@ -259,12 +259,10 @@ async def test_params_start_nodes_dom_node_not_element( ) -@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) @pytest.mark.asyncio -async def test_locate_by_context_invalid_context(bidi_session, inline, top_context, domain): - iframe_url_2 = inline("
foo
", domain=domain) - iframe_url_1 = inline(f"
", domain=domain) - page_url = inline(f"") +async def test_locate_by_context_invalid_context(bidi_session, inline, top_context, iframe): + iframe_url = inline(iframe("
foo
")) + page_url = inline(f"") await bidi_session.browsing_context.navigate( context=top_context["context"], url=page_url, wait="complete"