marionette: Pass params to NewWindow
The `NewWindow` Marionette command actually takes two arguments. They are optional, and without them, Firefox will open a new *tab* instead of a new *window*. Since we obviously want windows rather than tabs, so as to place them on separate monitors, we need to explicitly specify this when we execute the command.dev/ci
parent
ebb5318390
commit
38e826b454
|
@ -90,6 +90,30 @@ pub struct CloseWindowParams {
|
||||||
pub handle: String,
|
pub handle: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub enum WindowType {
|
||||||
|
Window,
|
||||||
|
Tab,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct NewWindowParams {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub window_type: WindowType,
|
||||||
|
pub focus: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct NewWindowResponse {
|
||||||
|
pub handle: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -124,7 +148,7 @@ pub enum Command {
|
||||||
#[serde(rename = "WebDriver:CloseWindow")]
|
#[serde(rename = "WebDriver:CloseWindow")]
|
||||||
CloseWindow(CloseWindowParams),
|
CloseWindow(CloseWindowParams),
|
||||||
#[serde(rename = "WebDriver:NewWindow")]
|
#[serde(rename = "WebDriver:NewWindow")]
|
||||||
NewWindow,
|
NewWindow(NewWindowParams),
|
||||||
#[serde(rename = "WebDriver:SwitchToWindow")]
|
#[serde(rename = "WebDriver:SwitchToWindow")]
|
||||||
SwitchToWindow(SwitchToWindowParams),
|
SwitchToWindow(SwitchToWindowParams),
|
||||||
#[serde(rename = "WebDriver:FullscreenWindow")]
|
#[serde(rename = "WebDriver:FullscreenWindow")]
|
||||||
|
|
|
@ -20,7 +20,8 @@ pub use error::{CommandError, ConnectionError, ErrorResponse, MessageError};
|
||||||
use message::{
|
use message::{
|
||||||
CloseWindowParams, Command, GetCurrentUrlResponse, GetTitleResponse,
|
CloseWindowParams, Command, GetCurrentUrlResponse, GetTitleResponse,
|
||||||
Hello, NavigateParams, NewSessionParams, NewSessionResponse,
|
Hello, NavigateParams, NewSessionParams, NewSessionResponse,
|
||||||
SwitchToWindowParams, WindowRect,
|
NewWindowParams, NewWindowResponse, SwitchToWindowParams, WindowRect,
|
||||||
|
WindowType,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
@ -184,8 +185,11 @@ impl Marionette {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fullscreen(&mut self) -> Result<(), CommandError> {
|
pub async fn fullscreen(&mut self) -> Result<(), CommandError> {
|
||||||
let res: serde_json::Value =
|
let res: serde_json::Value = self
|
||||||
self.conn.send_message(Command::FullscreenWindow).await?.unwrap();
|
.conn
|
||||||
|
.send_message(Command::FullscreenWindow)
|
||||||
|
.await?
|
||||||
|
.unwrap();
|
||||||
debug!("Received message: {:?}", res);
|
debug!("Received message: {:?}", res);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -247,9 +251,19 @@ impl Marionette {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_window(&mut self) -> Result<String, CommandError> {
|
pub async fn new_window(
|
||||||
let res: String =
|
&mut self,
|
||||||
self.conn.send_message(Command::NewWindow).await?.unwrap();
|
window_type: WindowType,
|
||||||
|
focus: bool,
|
||||||
|
) -> Result<String, CommandError> {
|
||||||
|
let res: NewWindowResponse = self
|
||||||
|
.conn
|
||||||
|
.send_message(Command::NewWindow(NewWindowParams {
|
||||||
|
window_type,
|
||||||
|
focus,
|
||||||
|
}))
|
||||||
|
.await?
|
||||||
|
.unwrap();
|
||||||
debug!("Received message: {:?}", res);
|
debug!("Received message: {:?}", res);
|
||||||
Ok(res.handle)
|
Ok(res.handle)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use tracing::{debug, error, info, trace, warn};
|
||||||
use crate::browser::{Browser, BrowserError};
|
use crate::browser::{Browser, BrowserError};
|
||||||
use crate::config::Configuration;
|
use crate::config::Configuration;
|
||||||
use crate::marionette::error::{CommandError, ConnectionError};
|
use crate::marionette::error::{CommandError, ConnectionError};
|
||||||
|
use crate::marionette::message::WindowType;
|
||||||
use crate::marionette::{Marionette, MarionetteConnection};
|
use crate::marionette::{Marionette, MarionetteConnection};
|
||||||
use crate::monitor::Monitor;
|
use crate::monitor::Monitor;
|
||||||
use crate::mqtt::{Message, MqttClient, MqttPublisher};
|
use crate::mqtt::{Message, MqttClient, MqttPublisher};
|
||||||
|
@ -149,7 +150,11 @@ impl Session {
|
||||||
monitor.y
|
monitor.y
|
||||||
);
|
);
|
||||||
if window.is_none() {
|
if window.is_none() {
|
||||||
window = Some(self.marionette.new_window().await?);
|
window = Some(
|
||||||
|
self.marionette
|
||||||
|
.new_window(WindowType::Window, false)
|
||||||
|
.await?,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let w = window.take().unwrap();
|
let w = window.take().unwrap();
|
||||||
self.marionette.switch_to_window(w.clone(), false).await?;
|
self.marionette.switch_to_window(w.clone(), false).await?;
|
||||||
|
|
Loading…
Reference in New Issue