Bug 1470098 - [wdspec] create_dialog and assert_dialog_handled have to use wdclient methods.. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 22 Jun 2018 10:34:34 +0200
changeset 814473 5e5801a2afbbcae154a5cd5638701ebe3d6ad23c
parent 814180 6c0fa9a675c91390ca27664ffb626c56e8afea4d
child 814474 621ee96b871ea35ea996b939e375ff10de77e403
push id115223
push userbmo:hskupin@gmail.com
push dateThu, 05 Jul 2018 12:38:59 +0000
bugs1470098
milestone63.0a1
Bug 1470098 - [wdspec] create_dialog and assert_dialog_handled have to use wdclient methods.. Both the 'create_dialog' and 'assert_dialog_handled' methods have to use the wdclient and not transport methods. MozReview-Commit-ID: 5QrznRN6qgq
testing/web-platform/tests/webdriver/tests/support/asserts.py
testing/web-platform/tests/webdriver/tests/support/fixtures.py
--- a/testing/web-platform/tests/webdriver/tests/support/asserts.py
+++ b/testing/web-platform/tests/webdriver/tests/support/asserts.py
@@ -1,11 +1,9 @@
-import os
-
-from webdriver import Element, WebDriverException
+from webdriver import Element, NoSuchAlertException, WebDriverException
 
 
 # WebDriver specification ID: dfn-error-response-data
 errors = {
     "element click intercepted": 400,
     "element not selectable": 400,
     "element not interactable": 400,
     "insecure certificate": 400,
@@ -85,29 +83,26 @@ def assert_success(response, value=None)
     assert response.status == 200, str(response.error)
 
     if value is not None:
         assert response.body["value"] == value
     return response.body.get("value")
 
 
 def assert_dialog_handled(session, expected_text):
-    result = session.transport.send("GET",
-                                    "session/%s/alert/text" % session.session_id)
-
     # If there were any existing dialogs prior to the creation of this
     # fixture's dialog, then the "Get Alert Text" command will return
     # successfully. In that case, the text must be different than that
     # of this fixture's dialog.
     try:
-        assert_error(result, "no such alert")
-    except:
-        assert (result.status == 200 and
-                result.body["value"] != expected_text), (
-            "Dialog with text '%s' was not handled." % expected_text)
+        assert session.alert.text != expected_text, (
+            "User prompt with text '%s' was not handled." % expected_text)
+
+    except NoSuchAlertException:
+        pass
 
 
 def assert_files_uploaded(session, element, files):
 
     def get_file_contents(file_index):
         return session.execute_async_script("""
             let files = arguments[0].files;
             let index = arguments[1];
--- a/testing/web-platform/tests/webdriver/tests/support/fixtures.py
+++ b/testing/web-platform/tests/webdriver/tests/support/fixtures.py
@@ -234,46 +234,39 @@ def url(server_config):
 
 def create_dialog(session):
     """Create a dialog (one of "alert", "prompt", or "confirm") and provide a
     function to validate that the dialog has been "handled" (either accepted or
     dismissed) by returning some value."""
 
     def create_dialog(dialog_type, text=None, result_var=None):
         assert dialog_type in ("alert", "confirm", "prompt"), (
-               "Invalid dialog type: '%s'" % dialog_type)
+            "Invalid dialog type: '%s'" % dialog_type)
 
         if text is None:
             text = ""
 
         assert isinstance(text, basestring), "`text` parameter must be a string"
 
         if result_var is None:
             result_var = "__WEBDRIVER"
 
         assert re.search(r"^[_$a-z$][_$a-z0-9]*$", result_var, re.IGNORECASE), (
             'The `result_var` must be a valid JavaScript identifier')
 
-        # Script completion and modal summoning are scheduled on two separate
-        # turns of the event loop to ensure that both occur regardless of how
-        # the user agent manages script execution.
-        spawn = """
-            var done = arguments[0];
-            setTimeout(done, 0);
+        # Script completes itself when the user prompt has been opened.
+        session.execute_async_script("""
             setTimeout(function() {{
                 window.{0} = window.{1}("{2}");
             }}, 0);
-        """.format(result_var, dialog_type, text)
+            """.format(result_var, dialog_type, text))
 
-        session.send_session_command("POST",
-                                     "execute/async",
-                                     {"script": spawn, "args": []})
         wait(session,
-             lambda s: s.send_session_command("GET", "alert/text") == text,
-             "modal has not appeared",
+             lambda s: s.alert.text == text,
+             "No user prompt with text '{}' detected".format(text),
              timeout=15,
              ignored_exceptions=webdriver.NoSuchAlertException)
 
     return create_dialog
 
 
 def clear_all_cookies(session):
     """Removes all cookies associated with the current active document"""