Bug 1569100 - Marionette: Add AcceptAlert, DismissAlert, GetAlertText and SendAlertText commands. r=ato

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nupur Baghel 2019-08-02 17:57:33 +00:00
Родитель eb1de83a74
Коммит af2197df27
2 изменённых файлов: 44 добавлений и 22 удалений

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

@ -40,8 +40,17 @@ pub struct WindowRect {
pub height: Option<i32>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Keys {
pub text: String,
pub value: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Command {
// Needs to be updated to "WebDriver:AcceptAlert" for Firefox 63
#[serde(rename = "WebDriver:AcceptDialog")]
AcceptAlert,
#[serde(
rename = "WebDriver:AddCookie",
serialize_with = "to_cookie",
@ -58,12 +67,16 @@ pub enum Command {
DeleteCookie(String),
#[serde(rename = "WebDriver:DeleteAllCookies")]
DeleteCookies,
#[serde(rename = "WebDriver:DismissAlert")]
DismissAlert,
#[serde(rename = "WebDriver:FindElement")]
FindElement(Locator),
#[serde(rename = "WebDriver:FindElements")]
FindElements(Locator),
#[serde(rename = "WebDriver:FullscreenWindow")]
FullscreenWindow,
#[serde(rename = "WebDriver:GetAlertText")]
GetAlertText,
#[serde(rename = "WebDriver:GetCookies")]
GetCookies,
#[serde(rename = "WebDriver:GetTimeouts")]
@ -80,6 +93,8 @@ pub enum Command {
MinimizeWindow,
#[serde(rename = "WebDriver:NewWindow")]
NewWindow(NewWindow),
#[serde(rename = "WebDriver:SendAlertText")]
SendAlertText(Keys),
#[serde(rename = "WebDriver:SetTimeouts")]
SetTimeouts(Timeouts),
#[serde(rename = "WebDriver:SetWindowRect")]
@ -137,6 +152,13 @@ mod tests {
assert_ser_de(&data, json);
}
#[test]
fn test_json_keys() {
let data = Keys {text: "Foo".into(), value: vec!["F".into(), "o".into(), "o".into()]};
let json = json!({"text": "Foo", "value": ["F", "o", "o"]});
assert_ser_de(&data, json);
}
#[test]
fn test_json_new_window() {
let data = NewWindow {

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

@ -7,7 +7,7 @@ use marionette_rs::common::{
};
use marionette_rs::message::{Command, Message, MessageId, Request};
use marionette_rs::webdriver::{
Command as MarionetteWebDriverCommand, Locator as MarionetteLocator,
Command as MarionetteWebDriverCommand, Keys as MarionetteKeys, Locator as MarionetteLocator,
NewWindow as MarionetteNewWindow, Selector as MarionetteSelector,
WindowRect as MarionetteWindowRect,
};
@ -43,7 +43,8 @@ use webdriver::command::WebDriverCommand::{
use webdriver::command::{
ActionsParameters, AddCookieParameters, GetNamedCookieParameters, GetParameters,
JavascriptCommandParameters, LocatorParameters, NewSessionParameters, NewWindowParameters,
SwitchToFrameParameters, SwitchToWindowParameters, TimeoutsParameters, WindowRectParameters,
SendKeysParameters, SwitchToFrameParameters, SwitchToWindowParameters, TimeoutsParameters,
WindowRectParameters,
};
use webdriver::command::{WebDriverCommand, WebDriverMessage};
use webdriver::common::{
@ -798,6 +799,7 @@ fn try_convert_to_marionette_message(
) -> WebDriverResult<Option<Command>> {
use self::WebDriverCommand::*;
Ok(match msg.command {
AcceptAlert => Some(Command::WebDriver(MarionetteWebDriverCommand::AcceptAlert)),
AddCookie(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::AddCookie(
x.to_marionette()?,
))),
@ -808,6 +810,7 @@ fn try_convert_to_marionette_message(
DeleteCookies => Some(Command::WebDriver(
MarionetteWebDriverCommand::DeleteCookies,
)),
DismissAlert => Some(Command::WebDriver(MarionetteWebDriverCommand::DismissAlert)),
FindElement(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::FindElement(
x.to_marionette()?,
))),
@ -817,6 +820,7 @@ fn try_convert_to_marionette_message(
FullscreenWindow => Some(Command::WebDriver(
MarionetteWebDriverCommand::FullscreenWindow,
)),
GetAlertText => Some(Command::WebDriver(MarionetteWebDriverCommand::GetAlertText)),
GetCookies | GetNamedCookie(_) => {
Some(Command::WebDriver(MarionetteWebDriverCommand::GetCookies))
}
@ -839,6 +843,9 @@ fn try_convert_to_marionette_message(
NewWindow(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::NewWindow(
x.to_marionette()?,
))),
SendAlertText(ref x) => Some(Command::WebDriver(
MarionetteWebDriverCommand::SendAlertText(x.to_marionette()?),
)),
SetTimeouts(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::SetTimeouts(
x.to_marionette()?,
))),
@ -897,10 +904,6 @@ impl MarionetteCommand {
} else {
let (opt_name, opt_parameters) = match msg.command {
Status => panic!("Got status command that should already have been handled"),
AcceptAlert => {
// Needs to be updated to "WebDriver:AcceptAlert" for Firefox 63
(Some("WebDriver:AcceptDialog"), None)
}
DeleteSession => {
let mut body = Map::new();
body.insert(
@ -909,7 +912,6 @@ impl MarionetteCommand {
);
(Some("Marionette:Quit"), Some(Ok(body)))
}
DismissAlert => (Some("WebDriver:DismissAlert"), None),
ElementClear(ref x) => (Some("WebDriver:ElementClear"), Some(x.to_marionette())),
ElementClick(ref x) => (Some("WebDriver:ElementClick"), Some(x.to_marionette())),
ElementSendKeys(ref e, ref x) => {
@ -953,7 +955,6 @@ impl MarionetteCommand {
(Some("WebDriver:FindElements"), Some(Ok(data)))
}
Get(ref x) => (Some("WebDriver:Navigate"), Some(x.to_marionette())),
GetAlertText => (Some("WebDriver:GetAlertText"), None),
GetActiveElement => (Some("WebDriver:GetActiveElement"), None),
GetCurrentUrl => (Some("WebDriver:GetCurrentURL"), None),
GetCSSValue(ref e, ref x) => {
@ -1009,20 +1010,6 @@ impl MarionetteCommand {
}
Refresh => (Some("WebDriver:Refresh"), None),
ReleaseActions => (Some("WebDriver:ReleaseActions"), None),
SendAlertText(ref x) => {
let mut data = Map::new();
data.insert("text".to_string(), Value::String(x.text.clone()));
data.insert(
"value".to_string(),
serde_json::to_value(
x.text
.chars()
.map(|x| x.to_string())
.collect::<Vec<String>>(),
)?,
);
(Some("WebDriver:SendAlertText"), Some(Ok(data)))
}
SwitchToFrame(ref x) => (Some("WebDriver:SwitchToFrame"), Some(x.to_marionette())),
SwitchToParentFrame => (Some("WebDriver:SwitchToParentFrame"), None),
SwitchToWindow(ref x) => {
@ -1550,6 +1537,19 @@ impl ToMarionette<MarionetteNewWindow> for NewWindowParameters {
}
}
impl ToMarionette<MarionetteKeys> for SendKeysParameters {
fn to_marionette(&self) -> WebDriverResult<MarionetteKeys> {
Ok(MarionetteKeys {
text: self.text.clone(),
value: self
.text
.chars()
.map(|x| x.to_string())
.collect::<Vec<String>>(),
})
}
}
impl ToMarionette<Map<String, Value>> for SwitchToFrameParameters {
fn to_marionette(&self) -> WebDriverResult<Map<String, Value>> {
let mut data = Map::new();