Bug 1885577 - [wdspec] Add tests for accessibility attributes locator for "browsingContext.locateNodes" command. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D207850
This commit is contained in:
Alexandra Borovova 2024-04-19 07:56:28 +00:00
Родитель 3fb9c3479e
Коммит 7bb3b39c6d
4 изменённых файлов: 270 добавлений и 13 удалений

Просмотреть файл

@ -59,10 +59,23 @@ async def test_params_locator_value_invalid_type(
)
@pytest.mark.parametrize("value", [None, False, 42, {}, []])
async def test_params_locator_accessability_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": "accessability", "value": value}
)
@pytest.mark.parametrize("type,value", [
("css", "a*b"),
("xpath", ""),
("innerText", "")
("innerText", ""),
("accessibility", {})
])
async def test_params_locator_value_invalid_value(bidi_session, inline, top_context, type, value):
await navigate_to_page(bidi_session, inline, top_context)

Просмотреть файл

@ -6,11 +6,17 @@ from ... import any_string, recursive_compare
@pytest.mark.parametrize("type,value", [
("css", "div"),
("xpath", "//div"),
("innerText", "foobarBARbaz")
("innerText", "foobarBARbaz"),
("accessibility", {"role": "banner"}),
("accessibility", {"name": "foo"}),
("accessibility", {"role": "banner", "name": "foo"}),
])
@pytest.mark.asyncio
async def test_find_by_locator(bidi_session, inline, top_context, type, value):
url = inline("""<div data-class="one">foobarBARbaz</div><div data-class="two">foobarBARbaz</div>""")
url = inline("""
<div data-class="one" role="banner" aria-label="foo">foobarBARbaz</div>
<div data-class="two" role="banner" aria-label="foo">foobarBARbaz</div>
""")
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
)
@ -165,3 +171,69 @@ async def test_find_by_inner_text(bidi_session, inline, top_context, locator, ex
)
recursive_compare(expected, result["nodes"])
@pytest.mark.parametrize(
"html,locator_value,expected_node_local_name",
[
(
"<article data-class='one'>foo</article><div data-class='two'>bar</div>",
{"role": "article"},
"article",
),
(
"<input role='searchbox' data-class='one' /><input data-class='two' type='text'/>",
{"role": "searchbox"},
"input",
),
(
"<button data-class='one'>Ok</button><button data-class='two'>Cancel</button>",
{"name": "Ok"},
"button",
),
(
"<button data-class='one' aria-labelledby='one two'></button><div id='one'>ok</div><div id='two'>go</div><button data-class='two'>Cancel</button>",
{"name": "ok go"},
"button",
),
(
"<button data-class='one' aria-label='foo'>bar</button><button data-class='two' aria-label='bar'>foo</button>",
{"name": "foo"},
"button",
),
(
"<div role='banner' aria-label='foo' data-class='one'></div><div role='banner' data-class='two'></div><div aria-label='foo' data-class='three'></div>",
{"role": "banner", "name": "foo"},
"div",
),
],
)
@pytest.mark.asyncio
async def test_locate_by_accessibility_attributes(
bidi_session,
inline,
top_context,
html,
locator_value,
expected_node_local_name,
):
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=inline(html), wait="complete"
)
expected = [
{
"type": "node",
"value": {
"attributes": {"data-class": "one"},
"localName": expected_node_local_name,
},
}
]
result = await bidi_session.browsing_context.locate_nodes(
context=top_context["context"],
locator={"type": "accessibility", "value": locator_value},
)
recursive_compare(expected, result["nodes"])

Просмотреть файл

@ -43,6 +43,45 @@ from ... import any_string, recursive_compare
},
}]
),
("accessibility", {"role": "banner"}, 1, [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("accessibility", {"name": "bar"}, 1, [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("accessibility", {"role": "banner", "name": "bar"}, 1, [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("css", "div", 10, [
{
"type": "node",
@ -114,18 +153,96 @@ from ... import any_string, recursive_compare
"nodeType": 1,
},
}]
)
),
("accessibility", {"role": "banner"}, 10, [
{
"type": "node",
"sharedId": any_string,
"value": {
"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"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("accessibility", {"name": "bar"}, 10, [
{
"type": "node",
"sharedId": any_string,
"value": {
"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"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("accessibility", {"role": "banner", "name": "bar"}, 10, [
{
"type": "node",
"sharedId": any_string,
"value": {
"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"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
], ids=[
"css_single",
"xpath_single",
"inner_text_single",
"accessibility_role_single",
"accessibility_name_single",
"accessibility_role_name_single",
"css_multiple",
"xpath_multiple",
"inner_text_multiple"
"inner_text_multiple",
"accessibility_role_multiple",
"accessibility_name_multiple",
"accessibility_role_name_multiple",
])
@pytest.mark.asyncio
async def test_find_by_locator_limit_return_count(bidi_session, inline, top_context, type, value, max_count, expected):
url = inline("""<div data-class="one">foo</div><div data-class="two">foo</div>""")
url = inline("""
<div data-class="one" role="banner" aria-label="bar">foo</div>
<div data-class="two" role="banner" aria-label="bar">foo</div>
""")
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
)

Просмотреть файл

@ -92,13 +92,59 @@ from ... import any_string, recursive_compare
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
}])
}]),
("accessibility", {"role": "banner"}, [{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "p",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
},
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"two"},
"childNodeCount": 1,
"localName": "p",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
}]),
("accessibility", {"name": "bar"}, [{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "p",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
}
]),
("accessibility", {"role": "banner", "name": "bar"}, [{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "p",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
}
}
])
])
@pytest.mark.asyncio
async def test_locate_with_context_nodes(bidi_session, inline, top_context, type, value, expected):
url = inline("""<div id="parent">
<p data-class="one">foo</p>
<p data-class="two">foo</p>
<p data-class="one" role="banner" aria-label="bar">foo</p>
<p data-class="two" role="banner">foo</p>
<a data-class="three">
<span id="text">bar</span>
</a>
@ -125,14 +171,23 @@ async def test_locate_with_context_nodes(bidi_session, inline, top_context, type
@pytest.mark.parametrize("type,value", [
("css", "p[data-class='one']"),
("xpath", ".//p[@data-class='one']"),
("innerText", "foo")
("innerText", "foo"),
("accessibility", {"role": "banner"}),
("accessibility", {"name": "bar"}),
("accessibility", {"role": "banner", "name": "bar"}),
])
@pytest.mark.asyncio
async def test_locate_with_multiple_context_nodes(bidi_session, inline, top_context, type, value):
url = inline("""
<div id="parent-one"><p data-class="one">foo</p><p data-class="two">bar</p></div>
<div id="parent-two"><p data-class="one">foo</p><p data-class="two">bar</p></div>
""")
<div id="parent-one">
<p data-class="one" role="banner" aria-label="bar">foo</p>
<p data-class="two">bar</p>
</div>
<div id="parent-two">
<p data-class="one" role="banner" aria-label="bar">foo</p>
<p data-class="two">bar</p>
</div>
""")
await bidi_session.browsing_context.navigate(
context=top_context["context"], url=url, wait="complete"
)