Skip to content

Commit

Permalink
[wdspec] add invalid context test
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Jan 13, 2025
1 parent de8a05c commit abb3ddb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
23 changes: 22 additions & 1 deletion webdriver/tests/bidi/browsing_context/locate_nodes/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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("<div>foo</div>", domain=domain)
iframe_url_1 = inline(f"<div><iframe src='{iframe_url_2}'></iframe></div>", domain=domain)
page_url = inline(f"<iframe src='{iframe_url_1}'></iframe>")

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"] }}
)
43 changes: 40 additions & 3 deletions webdriver/tests/bidi/browsing_context/locate_nodes/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<div id='in-iframe'>foo</div>", domain=domain)
page_url = inline(f"<iframe src='{iframe_url_1}'></iframe>")
iframe_url_1 = inline("<div>foo</div>", domain=domain)
page_url = inline(f"<iframe id='target' src='{iframe_url_1}'></iframe>")

await bidi_session.browsing_context.navigate(
context=top_context["context"], url=page_url, wait="complete"
Expand All @@ -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("<div>foo</div>", domain=domain)
iframe_url_1 = inline(f"<div><iframe id='target' src='{iframe_url_2}'></iframe></div>")
page_url = inline(f"<iframe src='{iframe_url_1}'></iframe>")

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",
Expand Down

0 comments on commit abb3ddb

Please sign in to comment.