22
33from ... import any_string , recursive_compare
44
5+ pytestmark = pytest .mark .asyncio
56
6- @pytest .mark .parametrize ("type,value" , [
7- ("css" , "div" ),
8- ("xpath" , "//div" ),
9- ("innerText" , "foobarBARbaz" ),
10- ("accessibility" , {"role" : "banner" }),
11- ("accessibility" , {"name" : "foo" }),
12- ("accessibility" , {"role" : "banner" , "name" : "foo" }),
13- ])
14- @pytest .mark .asyncio
7+
8+ @pytest .mark .parametrize (
9+ "type,value" ,
10+ [
11+ ("css" , "div" ),
12+ ("xpath" , "//div" ),
13+ ("innerText" , "foobarBARbaz" ),
14+ ("accessibility" , {"role" : "banner" }),
15+ ("accessibility" , {"name" : "foo" }),
16+ ("accessibility" , {"role" : "banner" , "name" : "foo" }),
17+ ],
18+ ids = ["css" , "xpath" , "innerText" , "a11y-role" , "a11y-name" , "a11y-both" ],
19+ )
1520async def test_find_by_locator (bidi_session , inline , top_context , type , value ):
1621 url = inline ("""
1722 <div data-class="one" role="banner" aria-label="foo">foobarBARbaz</div>
@@ -22,48 +27,85 @@ async def test_find_by_locator(bidi_session, inline, top_context, type, value):
2227 )
2328
2429 result = await bidi_session .browsing_context .locate_nodes (
25- context = top_context ["context" ],
26- locator = { "type" : type , "value" : value }
30+ context = top_context ["context" ], locator = {"type" : type , "value" : value }
2731 )
2832
2933 expected = [
3034 {
3135 "type" : "node" ,
3236 "sharedId" : any_string ,
3337 "value" : {
34- "attributes" : {"data-class" :"one" },
38+ "attributes" : {"data-class" : "one" },
3539 "childNodeCount" : 1 ,
3640 "localName" : "div" ,
3741 "namespaceURI" : "http://www.w3.org/1999/xhtml" ,
3842 "nodeType" : 1 ,
39- }
43+ },
4044 },
4145 {
4246 "type" : "node" ,
4347 "sharedId" : any_string ,
4448 "value" : {
45- "attributes" : {"data-class" :"two" },
49+ "attributes" : {"data-class" : "two" },
4650 "childNodeCount" : 1 ,
4751 "localName" : "div" ,
4852 "namespaceURI" : "http://www.w3.org/1999/xhtml" ,
4953 "nodeType" : 1 ,
50- }
51- }
54+ },
55+ },
5256 ]
5357
5458 recursive_compare (expected , result ["nodes" ])
5559
5660
57- @pytest .mark .asyncio
58- async def test_find_by_locator_select (bidi_session , inline , top_context ):
59- url = inline ("""<select></select>""" )
61+ @pytest .mark .parametrize ("value" , [":root" , "html" ])
62+ async def test_find_root_element_by_css_locator (
63+ bidi_session , inline , top_context , value
64+ ):
65+ await bidi_session .browsing_context .navigate (
66+ context = top_context ["context" ], url = inline ("<div>" ), wait = "complete"
67+ )
68+
69+ result = await bidi_session .browsing_context .locate_nodes (
70+ context = top_context ["context" ], locator = {"type" : "css" , "value" : value }
71+ )
72+
73+ expected = [
74+ {
75+ "type" : "node" ,
76+ "sharedId" : any_string ,
77+ "value" : {
78+ "attributes" : {},
79+ "childNodeCount" : 2 ,
80+ "localName" : "html" ,
81+ "namespaceURI" : "http://www.w3.org/1999/xhtml" ,
82+ "nodeType" : 1 ,
83+ },
84+ },
85+ ]
86+
87+ recursive_compare (expected , result ["nodes" ])
88+
89+
90+ @pytest .mark .parametrize (
91+ "html, selector" ,
92+ [
93+ ("<div></div>" , "div" ),
94+ ("<select></select>" , "select" ),
95+ ("<video></video>" , "video" ),
96+ ],
97+ ids = ["div" , "select" , "video" ],
98+ )
99+ async def test_no_user_agent_shadow_root (
100+ bidi_session , inline , top_context , html , selector
101+ ):
102+ url = inline (html )
60103 await bidi_session .browsing_context .navigate (
61104 context = top_context ["context" ], url = url , wait = "complete"
62105 )
63106
64107 result = await bidi_session .browsing_context .locate_nodes (
65- context = top_context ["context" ],
66- locator = { "type" : "css" , "value" : "select" }
108+ context = top_context ["context" ], locator = {"type" : "css" , "value" : selector }
67109 )
68110
69111 node_result = result ["nodes" ][0 ]
@@ -73,13 +115,13 @@ async def test_find_by_locator_select(bidi_session, inline, top_context):
73115 "value" : {
74116 "attributes" : {},
75117 "childNodeCount" : 0 ,
76- "localName" : "select" ,
118+ "localName" : selector ,
77119 "namespaceURI" : "http://www.w3.org/1999/xhtml" ,
78120 "nodeType" : 1 ,
79121 # Make sure user-agent shadow roots are not leaked by locateNodes
80122 # (eg Firefox uses shadow dom to implement the select widget).
81123 "shadowRoot" : None ,
82- }
124+ },
83125 }
84126 recursive_compare (expected , node_result )
85127
@@ -179,8 +221,9 @@ async def test_find_by_locator_select(bidi_session, inline, top_context):
179221 "ignore_case_true_partial_match_max_depth_two" ,
180222 "ignore_case_false_partial_match_max_depth_two" ,
181223])
182- @pytest .mark .asyncio
183- async def test_find_by_inner_text (bidi_session , inline , top_context , locator , expected_nodes_values ):
224+ async def test_find_by_inner_text (
225+ bidi_session , inline , top_context , locator , expected_nodes_values
226+ ):
184227 url = inline ("""<div>foo<span><strong>bar</strong></span><span>BAR</span>baz</div>""" )
185228 await bidi_session .browsing_context .navigate (
186229 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
237280 ),
238281 ],
239282)
240- @pytest .mark .asyncio
241283async def test_locate_by_accessibility_attributes (
242284 bidi_session ,
243285 inline ,
@@ -269,7 +311,6 @@ async def test_locate_by_accessibility_attributes(
269311
270312
271313@pytest .mark .parametrize ("domain" , ["" , "alt" ], ids = ["same_origin" , "cross_origin" ])
272- @pytest .mark .asyncio
273314async def test_locate_by_context (bidi_session , inline , top_context , domain ):
274315 iframe_url_1 = inline ("<div>foo</div>" , domain = domain )
275316 page_url = inline (f"<iframe id='target' src='{ iframe_url_1 } '></iframe>" )
@@ -304,7 +345,6 @@ async def test_locate_by_context(bidi_session, inline, top_context, domain):
304345
305346
306347@pytest .mark .parametrize ("domain" , ["" , "alt" ], ids = ["same_origin" , "cross_origin" ])
307- @pytest .mark .asyncio
308348async def test_locate_by_context_in_iframe (bidi_session , inline , top_context , domain ):
309349 iframe_url_2 = inline ("<div>foo</div>" , domain = domain )
310350 iframe_url_1 = inline (f"<div><iframe id='target' src='{ iframe_url_2 } '></iframe></div>" )
@@ -342,8 +382,9 @@ async def test_locate_by_context_in_iframe(bidi_session, inline, top_context, do
342382
343383@pytest .mark .parametrize ("domain" , ["" , "alt" ], ids = ["same_origin" , "cross_origin" ])
344384@pytest .mark .parametrize ("mode" , ["open" , "closed" ])
345- @pytest .mark .asyncio
346- async def test_locate_by_context_in_shadow_dom (bidi_session , inline , top_context , domain , mode ):
385+ async def test_locate_by_context_in_shadow_dom (
386+ bidi_session , inline , top_context , domain , mode
387+ ):
347388 iframe_url_1 = inline (f"<div>foo</div>" , domain = domain )
348389 page_url = inline (f"""
349390 <div id="host"></div>
0 commit comments