blob: 9147fb318326d918d9ea9137abae18f94cdeeeb4 [file] [log] [blame]
import pytest
from ... import any_string, recursive_compare
@pytest.mark.parametrize("type,value,max,expected", [
("css", "div", 1, [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("xpath", "//div", 1, [
{
"type": "node",
"sharedId": any_string,
"value": {
"attributes": {"data-class":"one"},
"childNodeCount": 1,
"localName": "div",
"namespaceURI": "http://www.w3.org/1999/xhtml",
"nodeType": 1,
},
}]
),
("innerText", "foo", 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",
"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,
},
}]
),
("xpath", "//div", 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,
},
}]
),
("innerText", "foo", 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",
"css_multiple",
"xpath_multiple",
"inner_text_multiple"
])
@pytest.mark.asyncio
async def test_find_by_css_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>""")
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": type, "value": value },
max_node_count = max_count
)
recursive_compare(expected, result["nodes"])