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,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[allow(dead_code)]
|
||||
|
@ -124,7 +148,7 @@ pub enum Command {
|
|||
#[serde(rename = "WebDriver:CloseWindow")]
|
||||
CloseWindow(CloseWindowParams),
|
||||
#[serde(rename = "WebDriver:NewWindow")]
|
||||
NewWindow,
|
||||
NewWindow(NewWindowParams),
|
||||
#[serde(rename = "WebDriver:SwitchToWindow")]
|
||||
SwitchToWindow(SwitchToWindowParams),
|
||||
#[serde(rename = "WebDriver:FullscreenWindow")]
|
||||
|
|
|
@ -20,7 +20,8 @@ pub use error::{CommandError, ConnectionError, ErrorResponse, MessageError};
|
|||
use message::{
|
||||
CloseWindowParams, Command, GetCurrentUrlResponse, GetTitleResponse,
|
||||
Hello, NavigateParams, NewSessionParams, NewSessionResponse,
|
||||
SwitchToWindowParams, WindowRect,
|
||||
NewWindowParams, NewWindowResponse, SwitchToWindowParams, WindowRect,
|
||||
WindowType,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
@ -184,8 +185,11 @@ impl Marionette {
|
|||
}
|
||||
|
||||
pub async fn fullscreen(&mut self) -> Result<(), CommandError> {
|
||||
let res: serde_json::Value =
|
||||
self.conn.send_message(Command::FullscreenWindow).await?.unwrap();
|
||||
let res: serde_json::Value = self
|
||||
.conn
|
||||
.send_message(Command::FullscreenWindow)
|
||||
.await?
|
||||
.unwrap();
|
||||
debug!("Received message: {:?}", res);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -247,9 +251,19 @@ impl Marionette {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
pub async fn new_window(&mut self) -> Result<String, CommandError> {
|
||||
let res: String =
|
||||
self.conn.send_message(Command::NewWindow).await?.unwrap();
|
||||
pub async fn new_window(
|
||||
&mut self,
|
||||
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);
|
||||
Ok(res.handle)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use tracing::{debug, error, info, trace, warn};
|
|||
use crate::browser::{Browser, BrowserError};
|
||||
use crate::config::Configuration;
|
||||
use crate::marionette::error::{CommandError, ConnectionError};
|
||||
use crate::marionette::message::WindowType;
|
||||
use crate::marionette::{Marionette, MarionetteConnection};
|
||||
use crate::monitor::Monitor;
|
||||
use crate::mqtt::{Message, MqttClient, MqttPublisher};
|
||||
|
@ -149,7 +150,11 @@ impl Session {
|
|||
monitor.y
|
||||
);
|
||||
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();
|
||||
self.marionette.switch_to_window(w.clone(), false).await?;
|
||||
|
|
Loading…
Reference in New Issue