From b2ef60224248577d1f6b10663eb176b4bb1b708d Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Mon, 23 Oct 2017 21:46:44 +0100 Subject: [PATCH] Bug 1411026 - Provide String type conversion for ErrorStatus. r=whimboo This allows us to construct an ErrorStatus variant from a String. This is useful if the remote end implementation uses the string codes for transport. The new From trait for ErrorStatus is a reverse lookup of ErrorStatus::error_code. It currently handles two cases of Selenium errors, which are "element not visible" and "invalid element coordinates". Both these have been deprecated in the WebDriver standard and we need to figure out a deprecation strategy for them. MozReview-Commit-ID: 48MAVNQoiKy --HG-- extra : rebase_source : 80c0932e3d42cfe19faa673d558790c83762dba1 --- testing/webdriver/src/error.rs | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/testing/webdriver/src/error.rs b/testing/webdriver/src/error.rs index 23b8302524ef..029e1462fc88 100644 --- a/testing/webdriver/src/error.rs +++ b/testing/webdriver/src/error.rs @@ -141,8 +141,8 @@ pub enum ErrorStatus { UnsupportedOperation, } - impl ErrorStatus { + /// Returns the string serialisation of the error type. pub fn error_code(&self) -> &'static str { use self::ErrorStatus::*; match *self { @@ -178,6 +178,7 @@ impl ErrorStatus { } } + /// Returns the correct HTTP status code associated with the error type. pub fn http_status(&self) -> StatusCode { use self::ErrorStatus::*; use self::StatusCode::*; @@ -215,6 +216,42 @@ impl ErrorStatus { } } +/// Deserialises error type from string. +impl From for ErrorStatus { + fn from(s: String) -> ErrorStatus { + use self::ErrorStatus::*; + match &*s { + "element click intercepted" => ElementClickIntercepted, + "element not interactable" | "element not visible" => ElementNotInteractable, + "element not selectable" => ElementNotSelectable, + "insecure certificate" => InsecureCertificate, + "invalid argument" => InvalidArgument, + "invalid cookie domain" => InvalidCookieDomain, + "invalid coordinates" | "invalid element coordinates" => InvalidCoordinates, + "invalid element state" => InvalidElementState, + "invalid selector" => InvalidSelector, + "invalid session id" => InvalidSessionId, + "javascript error" => JavascriptError, + "move target out of bounds" => MoveTargetOutOfBounds, + "no such alert" => NoSuchAlert, + "no such element" => NoSuchElement, + "no such frame" => NoSuchFrame, + "no such window" => NoSuchWindow, + "script timeout" => ScriptTimeout, + "session not created" => SessionNotCreated, + "stale element reference" => StaleElementReference, + "timeout" => Timeout, + "unable to capture screen" => UnableToCaptureScreen, + "unable to set cookie" => UnableToSetCookie, + "unexpected alert open" => UnexpectedAlertOpen, + "unknown command" => UnknownCommand, + "unknown error" => UnknownError, + "unsupported operation" => UnsupportedOperation, + _ => UnknownError, + } + } +} + pub type WebDriverResult = Result; #[derive(Debug)]