Bug 1484909 - [wdclient] Fix handling of "invalid session id" error.
authorHenrik Skupin <mail@hskupin.info>
Tue, 21 Aug 2018 09:15:21 +0200
changeset 487678 91baa8e095b50463d3c523ce580233cced01a02e
parent 487677 8e28ac045028ba46db9ea601bd1ae763a2e2c0c1
child 487679 3f99a091261fb67d798c7f16808d5a19efc7364b
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1484909
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 1484909 - [wdclient] Fix handling of "invalid session id" error. Without a session being created first the "send_command" method inappropriately checks for the "session not created" error, which only gets raised by the "new session" command. For all the other commands the "invalid session id" error has to be handled.
testing/web-platform/meta/webdriver/tests/delete_session/delete.py.ini
testing/web-platform/tests/tools/webdriver/webdriver/client.py
testing/web-platform/tests/webdriver/tests/delete_session/delete.py
deleted file mode 100644
--- a/testing/web-platform/meta/webdriver/tests/delete_session/delete.py.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[delete.py]
-  [test_dismissed_beforeunload_prompt]
-    expected: FAIL
-
--- a/testing/web-platform/tests/tools/webdriver/webdriver/client.py
+++ b/testing/web-platform/tests/tools/webdriver/webdriver/client.py
@@ -399,16 +399,23 @@ class Session(object):
 
     def __exit__(self, *args, **kwargs):
         self.end()
 
     def __del__(self):
         self.end()
 
     def start(self):
+        """Start a new WebDriver session.
+
+        :return: Dictionary with `capabilities` and `sessionId`.
+
+        :raises error.WebDriverException: If the remote end returns
+            an error.
+        """
         if self.session_id is not None:
             return
 
         body = {}
 
         if self.requested_capabilities is not None:
             body["capabilities"] = self.requested_capabilities
 
@@ -417,23 +424,23 @@ class Session(object):
         self.capabilities = value["capabilities"]
 
         if self.extension_cls:
             self.extension = self.extension_cls(self)
 
         return value
 
     def end(self):
-        """Tries to close the active session."""
+        """Try to close the active session."""
         if self.session_id is None:
             return
 
         try:
             self.send_command("DELETE", "session/%s" % self.session_id)
-        except error.SessionNotCreatedException:
+        except error.InvalidSessionIdException:
             pass
         finally:
             self.session_id = None
 
     def send_command(self, method, url, body=None):
         """
         Send a command to the remote end and validate its success.
 
@@ -441,30 +448,30 @@ class Session(object):
         :param uri: "Command part" of the HTTP request URL,
             e.g. `window/rect`.
         :param body: Optional body of the HTTP request.
 
         :return: `None` if the HTTP response body was empty, otherwise
             the `value` field returned after parsing the response
             body as JSON.
 
+        :raises error.WebDriverException: If the remote end returns
+            an error.
         :raises ValueError: If the response body does not contain a
             `value` key.
-        :raises error.WebDriverException: If the remote end returns
-            an error.
         """
         response = self.transport.send(
             method, url, body,
             encoder=protocol.Encoder, decoder=protocol.Decoder,
             session=self)
 
         if response.status != 200:
             err = error.from_response(response)
 
-            if isinstance(err, error.SessionNotCreatedException):
+            if isinstance(err, error.InvalidSessionIdException):
                 # The driver could have already been deleted the session.
                 self.session_id = None
 
             raise err
 
         if "value" in response.body:
             value = response.body["value"]
             """
@@ -490,24 +497,19 @@ class Session(object):
         :param url: "Command part" of the HTTP request URL,
             e.g. `window/rect`.
         :param body: Optional body of the HTTP request.  Must be JSON
             serialisable.
 
         :return: `None` if the HTTP response body was empty, otherwise
             the result of parsing the body as JSON.
 
-        :raises error.SessionNotCreatedException: If there is no active
-            session.
         :raises error.WebDriverException: If the remote end returns
             an error.
         """
-        if self.session_id is None:
-            raise error.SessionNotCreatedException()
-
         url = urlparse.urljoin("session/%s/" % self.session_id, uri)
         return self.send_command(method, url, body)
 
     @property
     @command
     def url(self):
         return self.send_session_command("GET", "url")
 
--- a/testing/web-platform/tests/webdriver/tests/delete_session/delete.py
+++ b/testing/web-platform/tests/webdriver/tests/delete_session/delete.py
@@ -8,16 +8,17 @@ from tests.support.inline import inline
 def delete_session(session):
     return session.transport.send("DELETE", "session/{session_id}".format(**vars(session)))
 
 
 def test_null_response_value(session):
     response = delete_session(session)
     value = assert_success(response)
     assert value is None
+
     # Need an explicit call to session.end() to notify the test harness
     # that a new session needs to be created for subsequent tests.
     session.end()
 
 
 def test_dismissed_beforeunload_prompt(session):
     session.url = inline("""
       <input type="text">