Skip to content

Commit 5d09b9e

Browse files
committed
add locate nodes tests
1 parent b5527b0 commit 5d09b9e

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

py/test/selenium/webdriver/common/bidi_browsing_context_tests.py

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ def test_pass_user_text_to_prompt(driver, pages):
303303
driver.browsing_context.handle_user_prompt(context=context_id, user_text=user_text)
304304

305305
# Check if the text was entered (this is browser-dependent)
306-
# In a real test, you might need to check a DOM element that displays the entered text
307306

308307

309308
def test_capture_screenshot(driver, pages):
@@ -415,3 +414,114 @@ def test_navigate_forward_in_browser_history(driver, pages):
415414
# Go forward
416415
driver.browsing_context.traverse_history(context=context_id, delta=1)
417416
WebDriverWait(driver, 5).until(EC.title_is("We Arrive Here"))
417+
418+
419+
# Tests for locate nodes
420+
def test_locate_nodes(driver, pages):
421+
"""Test locating nodes with CSS selector."""
422+
context_id = driver.current_window_handle
423+
424+
driver.get(pages.url("xhtmlTest.html"))
425+
426+
elements = driver.browsing_context.locate_nodes(context=context_id, locator={"type": "css", "value": "div"})
427+
428+
assert len(elements) > 0
429+
430+
431+
def test_locate_nodes_with_css_locator(driver, pages):
432+
"""Test locating nodes with specific CSS selector."""
433+
context_id = driver.current_window_handle
434+
435+
driver.get(pages.url("xhtmlTest.html"))
436+
437+
elements = driver.browsing_context.locate_nodes(
438+
context=context_id, locator={"type": "css", "value": "div.extraDiv, div.content"}, max_node_count=1
439+
)
440+
441+
assert len(elements) >= 1
442+
443+
value = elements[0]
444+
assert value["type"] == "node"
445+
assert "value" in value
446+
assert "localName" in value["value"]
447+
assert value["value"]["localName"] == "div"
448+
assert "attributes" in value["value"]
449+
assert "class" in value["value"]["attributes"]
450+
assert value["value"]["attributes"]["class"] == "content"
451+
452+
453+
def test_locate_nodes_with_xpath_locator(driver, pages):
454+
"""Test locating nodes with XPath selector."""
455+
context_id = driver.current_window_handle
456+
457+
driver.get(pages.url("xhtmlTest.html"))
458+
459+
elements = driver.browsing_context.locate_nodes(
460+
context=context_id, locator={"type": "xpath", "value": "/html/body/div[2]"}, max_node_count=1
461+
)
462+
463+
assert len(elements) >= 1
464+
465+
value = elements[0]
466+
assert value["type"] == "node"
467+
assert "value" in value
468+
assert "localName" in value["value"]
469+
assert value["value"]["localName"] == "div"
470+
assert "attributes" in value["value"]
471+
assert "class" in value["value"]["attributes"]
472+
assert value["value"]["attributes"]["class"] == "content"
473+
474+
475+
@pytest.mark.xfail_firefox
476+
def test_locate_nodes_with_inner_text(driver, pages):
477+
"""Test locating nodes with innerText selector."""
478+
context_id = driver.current_window_handle
479+
480+
driver.get(pages.url("xhtmlTest.html"))
481+
482+
elements = driver.browsing_context.locate_nodes(
483+
context=context_id, locator={"type": "innerText", "value": "Spaced out"}, max_node_count=1
484+
)
485+
486+
assert len(elements) >= 1
487+
488+
value = elements[0]
489+
assert value["type"] == "node"
490+
assert "value" in value
491+
492+
493+
def test_locate_nodes_with_max_node_count(driver, pages):
494+
"""Test locating nodes with maximum node count."""
495+
context_id = driver.current_window_handle
496+
497+
driver.get(pages.url("xhtmlTest.html"))
498+
499+
elements = driver.browsing_context.locate_nodes(
500+
context=context_id, locator={"type": "css", "value": "div"}, max_node_count=4
501+
)
502+
503+
assert len(elements) == 4
504+
505+
506+
def test_locate_nodes_given_start_nodes(driver, pages):
507+
"""Test locating nodes with start nodes."""
508+
context_id = driver.current_window_handle
509+
510+
driver.get(pages.url("formPage.html"))
511+
512+
form_elements = driver.browsing_context.locate_nodes(
513+
context=context_id, locator={"type": "css", "value": "form[name='login']"}
514+
)
515+
516+
assert len(form_elements) == 1
517+
518+
form_shared_id = form_elements[0]["sharedId"]
519+
520+
elements = driver.browsing_context.locate_nodes(
521+
context=context_id,
522+
locator={"type": "css", "value": "input"},
523+
start_nodes=[{"sharedId": form_shared_id}],
524+
max_node_count=50,
525+
)
526+
# The login form should have 3 input elements (email, age, and submit button)
527+
assert len(elements) == 3

0 commit comments

Comments
 (0)