Bug 1569100 - Add FindElements command and WebElements response types to Marionette. r=ato

Differential Revision: https://phabricator.services.mozilla.com/D39489

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nupur Baghel 2019-07-26 14:11:11 +00:00
Родитель a262ca312d
Коммит 90b33f2950
3 изменённых файлов: 29 добавлений и 18 удалений

Просмотреть файл

@ -1,6 +1,7 @@
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;
// TODO(nupur): Bug 1567165 - Make WebElement in Marionette a unit struct
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct WebElement {
#[serde(rename = "element-6066-11e4-a52e-4f735466cecf")]
@ -23,6 +24,7 @@ pub enum MarionetteResult {
Timeouts(Timeouts),
#[serde(deserialize_with = "from_value", serialize_with = "to_value")]
WebElement(WebElement),
WebElements(Vec<WebElement>),
#[serde(deserialize_with = "from_value", serialize_with = "to_empty_value")]
Null,
}
@ -78,7 +80,7 @@ mod tests {
let data = WebElement {
element: "foo".into(),
};
assert_ser_de(&data, json!({"element-6066-11e4-a52e-4f735466cecf": "foo"}));
assert_ser_de(&data, json!({ELEMENT_KEY: "foo"}));
}
#[test]
@ -109,6 +111,21 @@ mod tests {
);
}
#[test]
fn test_web_elements_response() {
let mut data = Vec::new();
data.push(WebElement {
element: "foo".into(),
});
data.push(WebElement {
element: "bar".into(),
});
assert_ser_de(
&MarionetteResult::WebElements(data),
json!([{ELEMENT_KEY: "foo"}, {ELEMENT_KEY: "bar"}]),
);
}
#[test]
fn test_timeouts_response() {
let data = Timeouts {

Просмотреть файл

@ -24,6 +24,8 @@ pub enum Selector {
pub enum Command {
#[serde(rename = "WebDriver:FindElement")]
FindElement(Locator),
#[serde(rename = "WebDriver:FindElements")]
FindElements(Locator),
#[serde(rename = "WebDriver:GetTimeouts")]
GetTimeouts,
}

Просмотреть файл

@ -793,15 +793,16 @@ fn try_convert_to_marionette_message(
msg: &WebDriverMessage<GeckoExtensionRoute>,
) -> WebDriverResult<Option<Command>> {
use self::WebDriverCommand::*;
match msg.command {
FindElement(ref x) => Ok(Some(Command::WebDriver(
MarionetteWebDriverCommand::FindElement(x.to_marionette()?),
Ok(match msg.command {
FindElement(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::FindElement(
x.to_marionette()?,
))),
GetTimeouts => Ok(Some(Command::WebDriver(
MarionetteWebDriverCommand::GetTimeouts,
))),
_ => Ok(None),
}
FindElements(ref x) => Some(Command::WebDriver(
MarionetteWebDriverCommand::FindElements(x.to_marionette()?),
)),
GetTimeouts => Some(Command::WebDriver(MarionetteWebDriverCommand::GetTimeouts)),
_ => None,
})
}
#[derive(Debug, PartialEq)]
@ -906,15 +907,6 @@ impl MarionetteCommand {
data.insert("element".to_string(), Value::String(e.to_string()));
(Some("WebDriver:FindElement"), Some(Ok(data)))
}
FindElements(ref x) => {
let data = try_opt!(
serde_json::to_value(x)?.as_object(),
ErrorStatus::UnknownError,
"Expected an object"
)
.clone();
(Some("WebDriver:FindElements"), Some(Ok(data)))
}
FindElementElements(ref e, ref x) => {
let mut data = try_opt!(
serde_json::to_value(x)?.as_object(),