From 86e4115d5bf658052f04d876772ef8228f630696 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Wed, 15 Apr 2015 13:38:01 +0100 Subject: [PATCH] Bug 1154691: Align Marionette with WebDriver errors Adds `invalid selector' and `invalid session id' errors to the server, and aligns the exceptions in the Python client with those in the server. Some of the exceptions are not in use yet and consequently do not carry a `code` property. This is fine because it makes us future-proof when the server starts using them. r=dburns --HG-- extra : source : cc8eb386f147893aaf867797eb9f3c6d8fd0925a --- .../client/marionette/b2g_update_test.py | 18 ++-- .../client/marionette/marionette_test.py | 4 +- .../driver/marionette_driver/errors.py | 86 +++++++++++-------- testing/marionette/error.js | 9 ++ 4 files changed, 66 insertions(+), 51 deletions(-) diff --git a/testing/marionette/client/marionette/b2g_update_test.py b/testing/marionette/client/marionette/b2g_update_test.py index 5c832922e469..3f7c8cfe1327 100644 --- a/testing/marionette/client/marionette/b2g_update_test.py +++ b/testing/marionette/client/marionette/b2g_update_test.py @@ -11,11 +11,11 @@ import time import types import weakref -from b2ginstance import B2GInstance -from marionette_driver.errors import InvalidResponseException from marionette_driver.marionette import Marionette from marionette_test import MarionetteTestCase from marionette_transport import MarionetteTransport + +from b2ginstance import B2GInstance from runtests import MarionetteTestRunner, cli class B2GUpdateMarionetteClient(MarionetteTransport): @@ -237,16 +237,10 @@ class B2GUpdateTestCase(MarionetteTestCase): self.print_status(status, os.path.basename(path)) - try: - results = self.marionette.execute_async_script(data, - script_args=[self.testvars], - special_powers=True) - self.handle_results(path, stage, results) - except InvalidResponseException, e: - # If the update test causes a restart, we will get an invalid - # response from the socket here. - if not will_restart: - raise e + results = self.marionette.execute_async_script(data, + script_args=[self.testvars], + special_powers=True) + self.handle_results(path, stage, results) def handle_results(self, path, stage, results): passed = results['passed'] diff --git a/testing/marionette/client/marionette/marionette_test.py b/testing/marionette/client/marionette/marionette_test.py index a1c56370d4df..bf6ed1f5f2ad 100644 --- a/testing/marionette/client/marionette/marionette_test.py +++ b/testing/marionette/client/marionette/marionette_test.py @@ -16,8 +16,8 @@ import warnings from marionette_driver.errors import ( - MarionetteException, InstallGeckoError, TimeoutException, InvalidResponseException, - JavascriptException, NoSuchElementException, XPathLookupException, NoSuchWindowException, + MarionetteException, TimeoutException, + JavascriptException, NoSuchElementException, NoSuchWindowException, StaleElementException, ScriptTimeoutException, ElementNotVisibleException, NoSuchFrameException, InvalidElementStateException, NoAlertPresentException, InvalidCookieDomainException, UnableToSetCookieException, InvalidSelectorException, diff --git a/testing/marionette/driver/marionette_driver/errors.py b/testing/marionette/driver/marionette_driver/errors.py index 34473cf7d443..d8256dca927b 100644 --- a/testing/marionette/driver/marionette_driver/errors.py +++ b/testing/marionette/driver/marionette_driver/errors.py @@ -49,8 +49,16 @@ class MarionetteException(Exception): return "".join(traceback.format_exception(self.__class__, msg, tb)) -class InstallGeckoError(MarionetteException): - pass +class ElementNotSelectableException(MarionetteException): + status = "element not selectable" + + +class InvalidArgumentException(MarionetteException): + status = "invalid argument" + + +class InvalidSessionIdException(MarionetteException): + status = "invalid session id" class TimeoutException(MarionetteException): @@ -58,11 +66,6 @@ class TimeoutException(MarionetteException): status = "timeout" -class InvalidResponseException(MarionetteException): - code = (53,) - status = "invalid response" - - class JavascriptException(MarionetteException): code = (17,) status = "javascript error" @@ -73,11 +76,6 @@ class NoSuchElementException(MarionetteException): status = "no such element" -class XPathLookupException(MarionetteException): - code = (19,) - status = "invalid xpath selector" - - class NoSuchWindowException(MarionetteException): code = (23,) status = "no such window" @@ -159,11 +157,6 @@ class FrameSendFailureError(MarionetteException): status = "frame send failure" -class UnsupportedOperationException(MarionetteException): - code = (405,) - status = "unsupported operation" - - class SessionNotCreatedException(MarionetteException): code = (33, 71) status = "session not created" @@ -173,31 +166,50 @@ class UnexpectedAlertOpen(MarionetteException): code = (26,) status = "unexpected alert open" + +class UnknownCommandException(MarionetteException): + code = (9,) + status = "unknown command" + + +class UnknownException(MarionetteException): + code = (13,) + status = "unknown error" + + +class UnsupportedOperationException(MarionetteException): + code = (405,) + status = "unsupported operation" + + excs = [ - MarionetteException, - TimeoutException, - InvalidResponseException, - JavascriptException, - NoSuchElementException, - XPathLookupException, - NoSuchWindowException, - StaleElementException, - ScriptTimeoutException, - ElementNotVisibleException, ElementNotAccessibleException, - NoSuchFrameException, - InvalidElementStateException, - NoAlertPresentException, - InvalidCookieDomainException, - UnableToSetCookieException, - InvalidElementCoordinates, - InvalidSelectorException, - MoveTargetOutOfBoundsException, - FrameSendNotInitializedError, + ElementNotSelectableException, + ElementNotVisibleException, FrameSendFailureError, - UnsupportedOperationException, + FrameSendNotInitializedError, + InvalidArgumentException, + InvalidCookieDomainException, + InvalidElementCoordinates, + InvalidElementStateException, + InvalidSelectorException, + InvalidSessionIdException, + JavascriptException, + MarionetteException, + MoveTargetOutOfBoundsException, + NoAlertPresentException, + NoSuchElementException, + NoSuchFrameException, + NoSuchWindowException, + ScriptTimeoutException, SessionNotCreatedException, + StaleElementException, + TimeoutException, + UnableToSetCookieException, UnexpectedAlertOpen, + UnknownCommandException, + UnknownException, + UnsupportedOperationException, ] diff --git a/testing/marionette/error.js b/testing/marionette/error.js index 4921af21d44d..0a916b420a1e 100644 --- a/testing/marionette/error.js +++ b/testing/marionette/error.js @@ -14,6 +14,7 @@ const errors = [ "IllegalArgumentError", "InvalidElementStateError", "InvalidSelectorError", + "InvalidSessionIdError", "JavaScriptError", "NoAlertOpenError", "NoSuchElementError", @@ -211,6 +212,14 @@ this.InvalidSelectorError = function(msg) { }; InvalidSelectorError.prototype = Object.create(WebDriverError.prototype); +this.InvalidSessionIdError = function(msg) { + WebDriverError.call(this, msg); + this.name = "InvalidSessionIdError"; + this.status = "invalid session id"; + this.code = 13; +}; +InvalidSessionIdError.prototype = Object.create(WebDriverError.prototype); + /** * Creates an error message for a JavaScript error thrown during * executeScript or executeAsyncScript.