Bug 1503015 - [wdspec] Add user prompt tests for element retrieval commands. r=ato
authorHenrik Skupin <mail@hskupin.info>
Tue, 30 Oct 2018 22:08:51 +0000
changeset 443648 f61505fe89301d998ad015166837ea301f1ec24c
parent 443647 cca1ea0c8558eab3db311a1523e58a03b806c788
child 443649 72c4825708d7635e82f5a1b171955cd392ef2009
push id109420
push useraciure@mozilla.com
push dateWed, 31 Oct 2018 05:11:56 +0000
treeherdermozilla-inbound@b357da105c49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1503015
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1503015 - [wdspec] Add user prompt tests for element retrieval commands. r=ato Depends on D10181 Differential Revision: https://phabricator.services.mozilla.com/D10182
testing/web-platform/tests/webdriver/tests/find_element/user_prompts.py
testing/web-platform/tests/webdriver/tests/find_element_from_element/user_prompts.py
testing/web-platform/tests/webdriver/tests/find_elements/user_prompts.py
testing/web-platform/tests/webdriver/tests/find_elements_from_element/user_prompts.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/find_element/user_prompts.py
@@ -0,0 +1,121 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import (
+    assert_error,
+    assert_same_element,
+    assert_success,
+    assert_dialog_handled,
+)
+from tests.support.inline import inline
+
+
+def find_element(session, using, value):
+    return session.transport.send(
+        "POST", "session/{session_id}/element".format(**vars(session)),
+        {"using": using, "value": value})
+
+
+@pytest.fixture
+def check_user_prompt_closed_without_exception(session, create_dialog):
+    def check_user_prompt_closed_without_exception(dialog_type, retval):
+        session.url = inline("<p>bar</p>")
+        element = session.find.css("p", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_element(session, "css selector", "p")
+        value = assert_success(response)
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+        assert_same_element(session, value, element)
+
+    return check_user_prompt_closed_without_exception
+
+
+@pytest.fixture
+def check_user_prompt_closed_with_exception(session, create_dialog):
+    def check_user_prompt_closed_with_exception(dialog_type, retval):
+        session.url = inline("<p>bar</p>")
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_element(session, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+    return check_user_prompt_closed_with_exception
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_but_exception(session, create_dialog):
+    def check_user_prompt_not_closed_but_exception(dialog_type):
+        session.url = inline("<p>bar</p>")
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_element(session, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+    return check_user_prompt_not_closed_but_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
+    check_user_prompt_not_closed_but_exception(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/find_element_from_element/user_prompts.py
@@ -0,0 +1,126 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import (
+    assert_error,
+    assert_same_element,
+    assert_success,
+    assert_dialog_handled,
+)
+from tests.support.inline import inline
+
+
+def find_element(session, element_id, using, value):
+    return session.transport.send(
+        "POST", "session/{session_id}/element/{element_id}/element".format(
+            session_id=session.session_id,
+            element_id=element_id),
+        {"using": using, "value": value})
+
+
+@pytest.fixture
+def check_user_prompt_closed_without_exception(session, create_dialog):
+    def check_user_prompt_closed_without_exception(dialog_type, retval):
+        session.url = inline("<div><p>bar</p><div>")
+        outer_element = session.find.css("div", all=False)
+        inner_element = session.find.css("p", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_element(session, outer_element.id, "css selector", "p")
+        value = assert_success(response)
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+        assert_same_element(session, value, inner_element)
+
+    return check_user_prompt_closed_without_exception
+
+
+@pytest.fixture
+def check_user_prompt_closed_with_exception(session, create_dialog):
+    def check_user_prompt_closed_with_exception(dialog_type, retval):
+        session.url = inline("<div><p>bar</p><div>")
+        outer_element = session.find.css("div", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_element(session, outer_element.id, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+    return check_user_prompt_closed_with_exception
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_but_exception(session, create_dialog):
+    def check_user_prompt_not_closed_but_exception(dialog_type):
+        session.url = inline("<div><p>bar</p><div>")
+        outer_element = session.find.css("div", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_element(session, outer_element.id, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+    return check_user_prompt_not_closed_but_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
+    check_user_prompt_not_closed_but_exception(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/find_elements/user_prompts.py
@@ -0,0 +1,123 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import (
+    assert_error,
+    assert_same_element,
+    assert_success,
+    assert_dialog_handled,
+)
+from tests.support.inline import inline
+
+
+def find_elements(session, using, value):
+    return session.transport.send(
+        "POST", "session/{session_id}/elements".format(**vars(session)),
+        {"using": using, "value": value})
+
+
+@pytest.fixture
+def check_user_prompt_closed_without_exception(session, create_dialog):
+    def check_user_prompt_closed_without_exception(dialog_type, retval):
+        session.url = inline("<p>bar</p>")
+        element = session.find.css("p", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_elements(session, "css selector", "p")
+        value = assert_success(response)
+        assert isinstance(value, list)
+        assert len(value) == 1
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+        assert_same_element(session, value[0], element)
+
+    return check_user_prompt_closed_without_exception
+
+
+@pytest.fixture
+def check_user_prompt_closed_with_exception(session, create_dialog):
+    def check_user_prompt_closed_with_exception(dialog_type, retval):
+        session.url = inline("<p>bar</p>")
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_elements(session, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+    return check_user_prompt_closed_with_exception
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_but_exception(session, create_dialog):
+    def check_user_prompt_not_closed_but_exception(dialog_type):
+        session.url = inline("<p>bar</p>")
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_elements(session, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+    return check_user_prompt_not_closed_but_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
+    check_user_prompt_not_closed_but_exception(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webdriver/tests/find_elements_from_element/user_prompts.py
@@ -0,0 +1,128 @@
+# META: timeout=long
+
+import pytest
+
+from tests.support.asserts import (
+    assert_error,
+    assert_same_element,
+    assert_success,
+    assert_dialog_handled,
+)
+from tests.support.inline import inline
+
+
+def find_elements(session, element_id, using, value):
+    return session.transport.send(
+        "POST", "session/{session_id}/element/{element_id}/elements".format(
+            session_id=session.session_id,
+            element_id=element_id),
+        {"using": using, "value": value})
+
+
+@pytest.fixture
+def check_user_prompt_closed_without_exception(session, create_dialog):
+    def check_user_prompt_closed_without_exception(dialog_type, retval):
+        session.url = inline("<div><p>bar</p><div>")
+        outer_element = session.find.css("div", all=False)
+        inner_element = session.find.css("p", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_elements(session, outer_element.id, "css selector", "p")
+        value = assert_success(response)
+        assert isinstance(value, list)
+        assert len(value) == 1
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+        assert_same_element(session, value[0], inner_element)
+
+    return check_user_prompt_closed_without_exception
+
+
+@pytest.fixture
+def check_user_prompt_closed_with_exception(session, create_dialog):
+    def check_user_prompt_closed_with_exception(dialog_type, retval):
+        session.url = inline("<div><p>bar</p><div>")
+        outer_element = session.find.css("div", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_elements(session, outer_element.id, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert_dialog_handled(session, expected_text=dialog_type, expected_retval=retval)
+
+    return check_user_prompt_closed_with_exception
+
+
+@pytest.fixture
+def check_user_prompt_not_closed_but_exception(session, create_dialog):
+    def check_user_prompt_not_closed_but_exception(dialog_type):
+        session.url = inline("<div><p>bar</p><div>")
+        outer_element = session.find.css("div", all=False)
+
+        create_dialog(dialog_type, text=dialog_type)
+
+        response = find_elements(session, outer_element.id, "css selector", "p")
+        assert_error(response, "unexpected alert open")
+
+        assert session.alert.text == dialog_type
+        session.alert.dismiss()
+
+    return check_user_prompt_not_closed_but_exception
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "accept and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", True),
+    ("prompt", ""),
+])
+def test_accept_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss(check_user_prompt_closed_without_exception, dialog_type, retval):
+    check_user_prompt_closed_without_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "dismiss and notify"})
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_dismiss_and_notify(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)
+
+
+@pytest.mark.capabilities({"unhandledPromptBehavior": "ignore"})
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
+def test_ignore(check_user_prompt_not_closed_but_exception, dialog_type):
+    check_user_prompt_not_closed_but_exception(dialog_type)
+
+
+@pytest.mark.parametrize("dialog_type, retval", [
+    ("alert", None),
+    ("confirm", False),
+    ("prompt", None),
+])
+def test_default(check_user_prompt_closed_with_exception, dialog_type, retval):
+    check_user_prompt_closed_with_exception(dialog_type, retval)