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<String> 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
This commit is contained in:
Andreas Tolfsen 2017-10-23 21:46:44 +01:00
parent dbf343872c
commit b2ef602242

View File

@ -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<String> 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<T> = Result<T, WebDriverError>;
#[derive(Debug)]