Bug 1486485 - [wdspec] Add test for empty text to send_alert_text/send.py. r=jgraham
authorHenrik Skupin <mail@hskupin.info>
Mon, 27 Aug 2018 17:39:04 +0200
changeset 491656 82dc592c7293290a7b17c4473c01a228e42615cd
parent 491655 f3ea8e9882548d737572d4c7a5a8d72518bf7183
child 491657 b7dada718ee0f14154562db052bfab83e9999a17
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgraham
bugs1486485
milestone63.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 1486485 - [wdspec] Add test for empty text to send_alert_text/send.py. r=jgraham The patch refactors the test file, and also adds an additional test, which makes sure that the default text of the prompt is replaced in case of an empty string is send as text.
testing/web-platform/tests/webdriver/tests/send_alert_text/send.py
--- a/testing/web-platform/tests/webdriver/tests/send_alert_text/send.py
+++ b/testing/web-platform/tests/webdriver/tests/send_alert_text/send.py
@@ -1,81 +1,65 @@
 import pytest
 
 from webdriver.transport import Response
 
 from tests.support.asserts import assert_error, assert_success
 from tests.support.inline import inline
 
 
+@pytest.fixture
+def page(session):
+    session.url = inline("""
+        <script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>
+    """)
+
+
 def send_alert_text(session, text=None):
     return session.transport.send(
         "POST", "session/{session_id}/alert/text".format(**vars(session)),
         {"text": text})
 
 
 def test_null_parameter_value(session, http):
     path = "/session/{session_id}/alert/text".format(**vars(session))
     with http.post(path, None) as response:
         assert_error(Response.from_http(response), "invalid argument")
 
 
-def test_null_response_value(session, url):
-    session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
-
+def test_null_response_value(session, page):
     response = send_alert_text(session, "Federer")
     value = assert_success(response)
     assert value is None
 
 
-def test_no_browsing_context(session, closed_window):
-    response = send_alert_text(session, "foo")
-    assert_error(response, "no such window")
+@pytest.mark.parametrize("text", [None, {}, [], 42, True])
+def test_invalid_input(session, page, text):
+    response = send_alert_text(session, text)
+    assert_error(response, "invalid argument")
 
 
-@pytest.mark.parametrize("text", [None, {}, [], 42, True])
-def test_invalid_input(session, text):
-    session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
-    response = send_alert_text(session, text)
-    assert_error(response, "invalid argument")
+def test_no_browsing_context(session, closed_window):
+    response = send_alert_text(session, "Federer")
+    assert_error(response, "no such window")
 
 
 def test_no_user_prompt(session):
     response = send_alert_text(session, "Federer")
     assert_error(response, "no such alert")
 
 
-def test_alert_element_not_interactable(session):
-    session.url = inline("<script>window.alert('Hello');</script>")
-
-    response = send_alert_text(session, "Federer")
-    assert_error(response, "element not interactable")
-
-
-def test_confirm_element_not_interactable(session):
-    session.url = inline("<script>window.confirm('Hello');</script>")
+@pytest.mark.parametrize("dialog_type", ["alert", "confirm"])
+def test_alert_element_not_interactable(session, dialog_type):
+    session.url = inline("<script>window.{}('Hello');</script>".format(dialog_type))
 
     response = send_alert_text(session, "Federer")
     assert_error(response, "element not interactable")
 
 
-def test_send_alert_text(session):
-    session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
-
-    send_response = send_alert_text(session, "Federer")
+@pytest.mark.parametrize("text", ["", "Federer", " Fed erer "])
+def test_send_alert_text(session, page, text):
+    send_response = send_alert_text(session, text)
     assert_success(send_response)
 
-    accept_response = session.transport.send("POST", "session/{session_id}/alert/accept"
-                                             .format(session_id=session.session_id))
-    assert_success(accept_response)
-    assert session.execute_script("return window.result") == "Federer"
-
+    session.alert.accept()
 
-def test_send_alert_text_with_whitespace(session):
-    session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
-
-    send_response = send_alert_text(session, " Fed erer ")
-    assert_success(send_response)
-
-    accept_response = session.transport.send("POST", "session/{session_id}/alert/accept"
-                                             .format(session_id=session.session_id))
-    assert_success(accept_response)
-    assert session.execute_script("return window.result") == " Fed erer "
+    assert session.execute_script("return window.result") == text