Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some shadow root tests #29924

Merged
merged 7 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/webdriver/webdriver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def from_json(cls, json, session):
class ShadowRoot(object):
identifier = "shadow-6066-11e4-a52e-4f735466cecf"

def __init__(self, session, id):
def __init__(self, id, session):
sarvaje marked this conversation as resolved.
Show resolved Hide resolved
"""
Construct a new shadow root representation.

Expand Down
14 changes: 6 additions & 8 deletions webdriver/tests/find_element_from_shadow_root/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_detached_shadow_root(session, get_shadow_page):
shadow_root = custom_element.shadow_root
session.refresh()

response = find_element(session, shadow_root.id, "css", "input")
response = find_element(session, shadow_root.id, "css selector", "input")
assert_error(response, "detached shadow root")


Expand All @@ -64,17 +64,15 @@ def test_found_element_equivalence(session, get_shadow_page):
expected = session.execute_script("return arguments[0].shadowRoot.querySelector('input')",
args=(custom_element,))
shadow_root = custom_element.shadow_root
response = find_element(session, shadow_root.id, "css", "input")
response = find_element(session, shadow_root.id, "css selector", "input")
value = assert_success(response)
assert_same_element(session, value, expected)


@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),
("partial link text", "link text"),
("tag name", "a"),
("xpath", "//a")])
whimboo marked this conversation as resolved.
Show resolved Hide resolved
("partial link text", "link text")])
def test_find_element(session, get_shadow_page, using, value):
# Step 8 - 9
session.url = get_shadow_page("<div><a href=# id=linkText>full link text</a></div>")
Expand All @@ -83,7 +81,7 @@ def test_find_element(session, get_shadow_page, using, value):
args=(custom_element,))
shadow_root = custom_element.shadow_root
response = find_element(session, shadow_root.id, using, value)
assert_success(response)
value = assert_success(response)
assert_same_element(session, value, expected)


Expand All @@ -104,7 +102,7 @@ def test_find_element_link_text(session, get_shadow_page, document, value):
shadow_root = custom_element.shadow_root

response = find_element(session, shadow_root.id, "link text", value)
assert_success(response)
value = assert_success(response)
assert_same_element(session, value, expected)


Expand All @@ -126,7 +124,7 @@ def test_find_element_partial_link_text(session, get_shadow_page, document, valu
shadow_root = custom_element.shadow_root

response = find_element(session, shadow_root.id, "partial link text", value)
assert_success(response)
value = assert_success(response)
assert_same_element(session, value, expected)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def find_element(session, shadow_id, using, value):
return session.transport.send(
"POST", "session/{session_id}/shadow/{shadow_id}/element".format(
session_id=session.session_id,
element_id=shadow_id),
shadow_id=shadow_id),
{"using": using, "value": value})


Expand Down
14 changes: 5 additions & 9 deletions webdriver/tests/find_elements_from_shadow_root/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def find_elements(session, shadow_id, using, value):
{"using": using, "value": value})


def test_null_parameter_value(session, http, inline):
session.url = inline("<div><a href=# id=linkText>full link text</a></div>")
def test_null_parameter_value(session, http, get_shadow_page):
session.url = get_shadow_page("<div><a href=# id=linkText>full link text</a></div>")
custom_element = session.find.css("custom-shadow-element", all=False)
shadow_root = custom_element.shadow_root

Expand Down Expand Up @@ -54,24 +54,22 @@ def test_detached_shadow_root(session, get_shadow_page):
shadow_root = custom_element.shadow_root
session.refresh()

response = find_elements(session, shadow_root.id, "css", "input")
response = find_elements(session, shadow_root.id, "css selector", "input")
assert_error(response, "detached shadow root")


def test_find_elements_equivalence(session, get_shadow_page):
session.url = get_shadow_page("<div><input id='check' type='checkbox'/><input id='text'/></div>")
custom_element = session.find.css("custom-shadow-element", all=False)
shadow_root = custom_element.shadow_root
response = find_elements(session, shadow_root.id, "css", "input")
response = find_elements(session, shadow_root.id, "css selector", "input")
assert_success(response)


@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),
("partial link text", "link text"),
("tag name", "a"),
("xpath", "//a")])
whimboo marked this conversation as resolved.
Show resolved Hide resolved
("partial link text", "link text")])
def test_find_elements(session, get_shadow_page, using, value):
# Step 8 - 9
session.url = get_shadow_page("<div><a href=# id=linkText>full link text</a></div>")
Expand All @@ -92,7 +90,6 @@ def test_find_elements(session, get_shadow_page, using, value):
def test_find_elements_link_text(session, get_shadow_page, document, value):
# Step 8 - 9
session.url = get_shadow_page("<div><a href=#>not wanted</a><br/>{0}</div>".format(document))
element = session.find.css("div", all=False)
custom_element = session.find.css("custom-shadow-element", all=False)
shadow_root = custom_element.shadow_root
expected = session.execute_script("return arguments[0].shadowRoot.querySelectorAll('a')[1]",
Expand All @@ -119,7 +116,6 @@ def test_find_elements_link_text(session, get_shadow_page, document, value):
def test_find_elements_partial_link_text(session, get_shadow_page, document, value):
# Step 8 - 9
session.url = get_shadow_page("<div><a href=#>not wanted</a><br/>{0}</div>".format(document))
element = session.find.css("div", all=False)
custom_element = session.find.css("custom-shadow-element", all=False)
shadow_root = custom_element.shadow_root
expected = session.execute_script("return arguments[0].shadowRoot.querySelectorAll('a')[1]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def find_elements(session, shadow_id, using, value):
return session.transport.send(
"POST", "session/{session_id}/shadow/{shadow_id}/elements".format(
session_id=session.session_id,
element_id=shadow_id),
shadow_id=shadow_id),
{"using": using, "value": value})


Expand Down
2 changes: 1 addition & 1 deletion webdriver/tests/get_element_shadow_root/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_no_top_browsing_context(session, closed_window):

session.window_handle = original_handle
response = get_shadow_root(session, element.id)
assert_error(response, "no such element")
assert_error(response, "stale element reference")
sarvaje marked this conversation as resolved.
Show resolved Hide resolved


def test_no_browsing_context(session, closed_frame):
Expand Down
2 changes: 2 additions & 0 deletions webdriver/tests/support/asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"unknown error": 500,
"unknown method": 405,
"unsupported operation": 500,
"detached shadow root": 404,
"no such shadow root": 404,
sarvaje marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down