Bug 1863266 - [wdspec] Improve tests for "Element Clear" and "Is Element Enabled" for disabled elements. r=webdriver-reviewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D193200
This commit is contained in:
Henrik Skupin 2024-04-16 18:31:40 +00:00
parent 6d07671d4b
commit 46c0a3721a
8 changed files with 323 additions and 152 deletions

View File

@ -0,0 +1,5 @@
def element_clear(session, element):
return session.transport.send(
"POST", "/session/{session_id}/element/{element_id}/clear".format(
session_id=session.session_id,
element_id=element.id))

View File

@ -8,6 +8,8 @@ from tests.support.asserts import (
assert_in_events,
assert_success,
)
from tests.support.dom import BUTTON_TYPES
from . import element_clear
@pytest.fixture
@ -19,13 +21,6 @@ def tracked_events():
]
def element_clear(session, element):
return session.transport.send(
"POST", "/session/{session_id}/element/{element_id}/clear".format(
session_id=session.session_id,
element_id=element.id))
@pytest.fixture(scope="session")
def text_file(tmpdir_factory):
fh = tmpdir_factory.mktemp("tmp").join("hello.txt")
@ -179,31 +174,6 @@ def test_input(session, inline, add_event_listeners, tracked_events, type, value
assert_element_has_focus(session.execute_script("return document.body"))
@pytest.mark.parametrize("type",
["number",
"range",
"email",
"password",
"search",
"tel",
"text",
"url",
"color",
"date",
"datetime",
"datetime-local",
"time",
"month",
"week",
"file"])
def test_input_disabled(session, inline, type):
session.url = inline("<input type=%s disabled>" % type)
element = session.find.css("input", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
@pytest.mark.parametrize("type",
["number",
"range",
@ -241,14 +211,6 @@ def test_textarea(session, inline, add_event_listeners, tracked_events):
assert_in_events(session, ["focus", "change", "blur"])
def test_textarea_disabled(session, inline):
session.url = inline("<textarea disabled></textarea>")
element = session.find.css("textarea", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_textarea_readonly(session, inline):
session.url = inline("<textarea readonly></textarea>")
element = session.find.css("textarea", all=False)
@ -278,26 +240,12 @@ def test_input_file_multiple(session, text_file, inline):
assert element.property("value") == ""
def test_select(session, inline):
session.url = inline("""
<select>
<option>foo
</select>
""")
select = session.find.css("select", all=False)
option = session.find.css("option", all=False)
@pytest.mark.parametrize("type", BUTTON_TYPES)
def test_button(session, inline, type):
session.url = inline(f"""<button type="{type}">""")
element = session.find.css("button", all=False)
response = element_clear(session, select)
assert_error(response, "invalid element state")
response = element_clear(session, option)
assert_error(response, "invalid element state")
def test_button(session, inline):
session.url = inline("<button></button>")
button = session.find.css("button", all=False)
response = element_clear(session, button)
response = element_clear(session, element)
assert_error(response, "invalid element state")

View File

@ -0,0 +1,113 @@
import pytest
from tests.support.asserts import assert_error, assert_success
from tests.support.dom import BUTTON_TYPES, INPUT_TYPES
from . import element_clear
@pytest.mark.parametrize("type", BUTTON_TYPES)
def test_button(session, inline, type):
session.url = inline(f"""<button type="{type}" disabled>""")
element = session.find.css("button", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
@pytest.mark.parametrize("type", INPUT_TYPES)
def test_input(session, inline, type):
session.url = inline(f"""<input type="{type}" disabled>""")
element = session.find.css("input", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_textarea(session, inline):
session.url = inline("<textarea disabled></textarea>")
element = session.find.css("textarea", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_fieldset_descendant(session, inline):
session.url = inline("<fieldset disabled><input>foo")
element = session.find.css("input", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_fieldset_descendant_first_legend(session, inline):
session.url = inline("<fieldset disabled><legend><input>foo")
element = session.find.css("input", all=False)
response = element_clear(session, element)
assert_success(response)
def test_fieldset_descendant_not_first_legend(session, inline):
session.url = inline("<fieldset disabled><legend></legend><legend><input>foo")
element = session.find.css("input", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_option(session, inline):
session.url = inline("<select><option disabled>foo")
element = session.find.css("option", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_option_optgroup(session, inline):
session.url = inline("<select><optgroup disabled><option>foo")
element = session.find.css("option", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_option_select(session, inline):
session.url = inline("<select disabled><option>foo")
element = session.find.css("option", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_optgroup_select(session, inline):
session.url = inline("<select disabled><optgroup>foo")
element = session.find.css("optgroup", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
def test_select(session, inline):
session.url = inline("<select disabled>")
element = session.find.css("select", all=False)
response = element_clear(session, element)
assert_error(response, "invalid element state")
@pytest.mark.parametrize("tagname", ["button", "input", "select", "textarea"])
def test_xhtml(session, inline, tagname):
session.url = inline(
f"""<{tagname} disabled="disabled"></{tagname}>""", doctype="xhtml")
element = session.find.css(tagname, all=False)
result = element_clear(session, element)
assert_error(result, "invalid element state")
def test_xml(session, inline):
session.url = inline("""<note></note>""", doctype="xml")
element = session.find.css("note", all=False)
result = element_clear(session, element)
assert_error(result, "invalid element state")

View File

@ -3,13 +3,7 @@
import pytest
from tests.support.asserts import assert_dialog_handled, assert_error, assert_success
def element_clear(session, element):
return session.transport.send(
"POST", "/session/{session_id}/element/{element_id}/clear".format(
session_id=session.session_id,
element_id=element.id))
from . import element_clear
@pytest.fixture

View File

@ -0,0 +1,8 @@
def is_element_enabled(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/enabled".format(
session_id=session.session_id,
element_id=element_id
)
)

View File

@ -3,16 +3,8 @@ import pytest
from webdriver import WebElement
from tests.support.asserts import assert_error, assert_success
def is_element_enabled(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/enabled".format(
session_id=session.session_id,
element_id=element_id
)
)
from tests.support.dom import BUTTON_TYPES, INPUT_TYPES
from . import is_element_enabled
def test_no_top_browsing_context(session, closed_window):
@ -90,80 +82,171 @@ def test_stale_element_reference(session, stale_element, as_frame):
assert_error(result, "stale element reference")
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_form_control_disabled(session, inline, element):
session.url = inline("<{} disabled/>".format(element))
element = session.find.css(element, all=False)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
@pytest.mark.parametrize("type", BUTTON_TYPES)
def test_button(session, inline, status, expected, type):
session.url = inline(f"""<button type="{type}" {status}>""")
element = session.find.css("button", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
@pytest.mark.parametrize("type", INPUT_TYPES)
def test_input(session, inline, status, expected, type):
session.url = inline(f"""<input type="{type}" {status}>""")
element = session.find.css("input", all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)
assert_success(result, expected)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_form_control_enabled(session, inline, element):
session.url = inline("<{}/>".format(element))
element = session.find.css(element, all=False)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_textarea(session, inline, status, expected):
session.url = inline(f"<textarea {status}></textarea>")
element = session.find.css("textarea", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_fieldset(session, inline, status, expected):
session.url = inline(f"<fieldset {status}><input>foo")
element = session.find.css("input", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_fieldset_descendant(session, inline, status, expected):
session.url = inline(f"<fieldset {status}><input>foo")
element = session.find.css("input", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", True),
], ids=["enabled", "disabled"])
def test_fieldset_descendant_first_legend(session, inline, status, expected):
session.url = inline(f"<fieldset {status}><legend><input>foo")
element = session.find.css("input", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_fieldset_descendant_not_first_legend(session, inline, status, expected):
session.url = inline(f"<fieldset {status}><legend></legend><legend><input>foo")
element = session.find.css("input", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_option(session, inline, status, expected):
session.url = inline(f"<select><option {status}>foo")
element = session.find.css("option", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_option_with_optgroup(session, inline, status, expected):
session.url = inline(f"<select><optgroup {status}><option>foo")
element = session.find.css("optgroup", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
option = session.find.css("option", all=False)
response = is_element_enabled(session, option.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_option_with_select(session, inline, status, expected):
session.url = inline(f"<select {status}><option>foo")
option = session.find.css("option", all=False)
response = is_element_enabled(session, option.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_optgroup_with_select(session, inline, status, expected):
session.url = inline(f"<select {status}><optgroup>foo")
option = session.find.css("optgroup", all=False)
response = is_element_enabled(session, option.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled", False),
], ids=["enabled", "disabled"])
def test_select(session, inline, status, expected):
session.url = inline(f"<select {status}>")
element = session.find.css("select", all=False)
response = is_element_enabled(session, element.id)
assert_success(response, expected)
@pytest.mark.parametrize("status, expected", [
("", True),
("disabled=\"disabled\"", False),
], ids=["enabled", "disabled"])
@pytest.mark.parametrize("tagname", ["button", "input", "select", "textarea"])
def test_xhtml(session, inline, status, expected, tagname):
session.url = inline(
f"""<{tagname} {status}></{tagname}>""", doctype="xhtml")
element = session.find.css(tagname, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
assert_success(result, expected)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_disabled_descendant(session, inline, element):
session.url = inline("<fieldset disabled><{}/></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_enabled_descendant(session, inline, element):
session.url = inline("<fieldset><{}/></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_disabled_descendant_legend(session, inline, element):
session.url = inline("<fieldset disabled><legend><{}/></legend></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_fieldset_enabled_descendant_legend(session, inline, element):
session.url = inline("<fieldset><legend><{}/></legend></fieldset>".format(element))
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_xhtml_form_control_disabled(session, inline, element):
session.url = inline("""<{} disabled="disabled"/>""".format(element),
doctype="xhtml")
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, False)
@pytest.mark.parametrize("element", ["button", "input", "select", "textarea"])
def test_xhtml_form_control_enabled(session, inline, element):
session.url = inline("""<{}/>""".format(element), doctype="xhtml")
element = session.find.css(element, all=False)
result = is_element_enabled(session, element.id)
assert_success(result, True)
def test_xml_always_not_enabled(session, inline):
def test_xml(session, inline):
session.url = inline("""<note></note>""", doctype="xml")
element = session.find.css("note", all=False)

View File

@ -3,16 +3,7 @@
import pytest
from tests.support.asserts import assert_error, assert_dialog_handled, assert_success
def is_element_enabled(session, element_id):
return session.transport.send(
"GET",
"session/{session_id}/element/{element_id}/enabled".format(
session_id=session.session_id,
element_id=element_id
)
)
from . import is_element_enabled
@pytest.fixture

View File

@ -0,0 +1,29 @@
BUTTON_TYPES = [
"button",
"reset",
"submit",
]
INPUT_TYPES = [
"button",
"checkbox",
"color",
"date",
"datetime-local",
"email",
"file",
"image",
"month",
"number",
"password",
"radio",
"range",
"reset",
"search",
"submit",
"tel",
"text",
"time",
"url",
"week",
];