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

[Gecko Bug 1811545] [wdspec] Enhance stale_element fixture for shadow root nodes. #38208

Merged
merged 5 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 18 additions & 8 deletions webdriver/tests/element_clear/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def test_no_such_element_with_invalid_value(session):
assert_error(response, "no such element")


def test_no_such_element_with_shadow_root(session, get_test_page):
session.url = get_test_page()

element = session.find.css("custom-element", all=False)

result = element_clear(session, element.shadow_root)
assert_error(result, "no such element")


@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_window_handle(session, inline, closed):
session.url = inline("<div id='parent'><p/>")
Expand All @@ -89,25 +98,26 @@ def test_no_such_element_from_other_window_handle(session, inline, closed):


@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_frame(session, url, closed):
session.url = url("/webdriver/tests/support/html/subframe.html")
def test_no_such_element_from_other_frame(session, get_test_page, closed):
session.url = get_test_page(as_frame=True)

frame = session.find.css("#delete-frame", all=False)
frame = session.find.css("iframe", all=False)
session.switch_frame(frame)

button = session.find.css("#remove-parent", all=False)
if closed:
button.click()
element = session.find.css("div", all=False)

session.switch_frame("parent")

response = element_clear(session, button)
if closed:
session.execute_script("arguments[0].remove();", args=[frame])

response = element_clear(session, element)
assert_error(response, "no such element")


@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_stale_element_reference(session, stale_element, as_frame):
element = stale_element("<input>", "input", as_frame=as_frame)
element = stale_element("input#text", as_frame=as_frame)

response = element_clear(session, element)
assert_error(response, "stale element reference")
Expand Down
26 changes: 18 additions & 8 deletions webdriver/tests/element_click/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def test_no_such_element_with_invalid_value(session):
assert_error(response, "no such element")


def test_no_such_element_with_shadow_root(session, get_test_page):
session.url = get_test_page()

element = session.find.css("custom-element", all=False)

result = element_click(session, element.shadow_root)
assert_error(result, "no such element")


@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_window_handle(session, inline, closed):
session.url = inline("<div id='parent'><p/>")
Expand All @@ -65,25 +74,26 @@ def test_no_such_element_from_other_window_handle(session, inline, closed):


@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_frame(session, url, closed):
session.url = url("/webdriver/tests/support/html/subframe.html")
def test_no_such_element_from_other_frame(session, get_test_page, closed):
session.url = get_test_page(as_frame=True)

frame = session.find.css("#delete-frame", all=False)
frame = session.find.css("iframe", all=False)
session.switch_frame(frame)

button = session.find.css("#remove-parent", all=False)
if closed:
button.click()
element = session.find.css("input#text", all=False)

session.switch_frame("parent")

response = element_click(session, button)
if closed:
session.execute_script("arguments[0].remove();", args=[frame])

response = element_click(session, element)
assert_error(response, "no such element")


@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_stale_element_reference(session, stale_element, as_frame):
element = stale_element("<div>", "div", as_frame=as_frame)
element = stale_element("input#text", as_frame=as_frame)

response = element_click(session, element)
assert_error(response, "stale element reference")
108 changes: 30 additions & 78 deletions webdriver/tests/element_click/shadow_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,45 @@ def element_click(session, element):
element_id=element.id))


@pytest.fixture
def get_checkbox_dom(inline):
return inline("""
<style>
custom-checkbox-element {
display:block; width:20px; height:20px;
}
</style>
<custom-checkbox-element></custom-checkbox-element>
<script>
customElements.define('custom-checkbox-element',
class extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'}).innerHTML = `
<div><input type="checkbox"/></div>
`;
}
});
</script>""")


@pytest.mark.parametrize("click_on", ["custom_element", "checkbox_element"])
def test_shadow_element_click(session, get_checkbox_dom, click_on):
session.url = get_checkbox_dom
custom_element = session.find.css("custom-checkbox-element", all=False)
checkbox_element = session.execute_script("return arguments[0].shadowRoot.querySelector('input')",
args=(custom_element,))
is_pre_checked = session.execute_script("return arguments[0].checked",
args=(checkbox_element,))
@pytest.mark.parametrize("click_on", ["host_element", "checkbox_element"])
def test_shadow_element_click(session, get_test_page, click_on):
session.url = get_test_page()

host_element = session.find.css("custom-element", all=False)
checkbox_element = session.execute_script("""
return arguments[0].shadowRoot.querySelector("input")
""", args=(host_element,))

is_pre_checked = session.execute_script("""
return arguments[0].checked
""", args=(checkbox_element,))
assert is_pre_checked == False

response = element_click(session, locals()[click_on])
assert_success(response)
is_post_checked = session.execute_script("return arguments[0].checked",
args=(checkbox_element,))

is_post_checked = session.execute_script("""
return arguments[0].checked
""", args=(checkbox_element,))
assert is_post_checked == True


@pytest.fixture
def get_nested_shadow_checkbox_dom(inline):
return inline("""
<style>
custom-nesting-element {
display:block; width:20px; height:20px;
}
</style>
<custom-nesting-element></custom-nesting-element>
<script>
customElements.define('custom-nesting-element',
class extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'}).innerHTML = `
<style>
custom-checkbox-element {
display:block; width:20px; height:20px;
}
</style>
<div><custom-checkbox-element></custom-checkbox-element></div>
`;
}
});
customElements.define('custom-checkbox-element',
class extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'}).innerHTML = `
<div><input type="checkbox"/></div>
`;
}
});
</script>""")
@pytest.mark.parametrize("click_on", ["outer_element", "inner_element", "checkbox"])
def test_nested_shadow_element_click(session, get_test_page, click_on):
session.url = get_test_page(nested_shadow_dom=True)

outer_element = session.find.css("custom-element", all=False)
inner_element = session.execute_script("""
return arguments[0].shadowRoot.querySelector("inner-custom-element")
""", args=(outer_element,))
checkbox = session.execute_script("""
return arguments[0].shadowRoot.querySelector("input")
""", args=(inner_element,))

@pytest.mark.parametrize("click_on", ["outer_element", "inner_element", "checkbox_element"])
def test_nested_shadow_element_click(session, get_nested_shadow_checkbox_dom, click_on):
session.url = get_nested_shadow_checkbox_dom
outer_element = session.find.css("custom-nesting-element", all=False)
inner_element = session.execute_script("return arguments[0].shadowRoot.querySelector('custom-checkbox-element')",
args=(outer_element,))
checkbox_element = session.execute_script("return arguments[0].shadowRoot.querySelector('input')",
args=(inner_element,))
is_pre_checked = session.execute_script("return arguments[0].checked",
args=(checkbox_element,))
is_pre_checked = session.execute_script("return arguments[0].checked", args=(checkbox,))
assert is_pre_checked == False

click_response = element_click(session, locals()[click_on])
assert_success(click_response)
is_post_checked = session.execute_script("return arguments[0].checked",
args=(checkbox_element,))
is_post_checked = session.execute_script("return arguments[0].checked", args=(checkbox,))
assert is_post_checked == True
26 changes: 18 additions & 8 deletions webdriver/tests/element_send_keys/send_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ def test_no_such_element_with_invalid_value(session):
assert_error(response, "no such element")


def test_no_such_element_with_shadow_root(session, get_test_page):
session.url = get_test_page()

element = session.find.css("custom-element", all=False)

result = element_send_keys(session, element.shadow_root, "foo")
assert_error(result, "no such element")


@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_window_handle(session, inline, closed):
session.url = inline("<div id='parent'><p/>")
Expand All @@ -78,25 +87,26 @@ def test_no_such_element_from_other_window_handle(session, inline, closed):


@pytest.mark.parametrize("closed", [False, True], ids=["open", "closed"])
def test_no_such_element_from_other_frame(session, url, closed):
session.url = url("/webdriver/tests/support/html/subframe.html")
def test_no_such_element_from_other_frame(session, get_test_page, closed):
session.url = get_test_page(as_frame=True)

frame = session.find.css("#delete-frame", all=False)
frame = session.find.css("iframe", all=False)
session.switch_frame(frame)

button = session.find.css("#remove-parent", all=False)
if closed:
button.click()
element = session.find.css("input#text", all=False)

session.switch_frame("parent")

response = element_send_keys(session, button, "foo")
if closed:
session.execute_script("arguments[0].remove();", args=[frame])

response = element_send_keys(session, element, "foo")
assert_error(response, "no such element")


@pytest.mark.parametrize("as_frame", [False, True], ids=["top_context", "child_context"])
def test_stale_element_reference(session, stale_element, as_frame):
element = stale_element("<input>", "input", as_frame=as_frame)
element = stale_element("input#text", as_frame=as_frame)

response = element_send_keys(session, element, "foo")
assert_error(response, "stale element reference")
Expand Down
Loading