use super::ChromeCommand;
use super::NetworkConditions;
use crate::error::WebDriverResult;
use crate::session::handle::SessionHandle;
use serde_json::{Value, json};
use std::sync::Arc;
#[deprecated(since = "0.37.0", note = "use WebDriver::cdp() / thirtyfour::cdp::Cdp instead")]
#[derive(Debug, Clone)]
pub struct ChromeDevTools {
pub handle: Arc<SessionHandle>,
}
impl ChromeDevTools {
pub fn new(handle: Arc<SessionHandle>) -> Self {
Self {
handle,
}
}
pub async fn launch_app(&self, app_id: &str) -> WebDriverResult<()> {
self.handle.cmd(ChromeCommand::LaunchApp(app_id.to_string())).await?;
Ok(())
}
pub async fn get_network_conditions(&self) -> WebDriverResult<NetworkConditions> {
let v = self.handle.cmd(ChromeCommand::GetNetworkConditions).await?;
v.value()
}
pub async fn set_network_conditions(
&self,
conditions: &NetworkConditions,
) -> WebDriverResult<()> {
self.handle.cmd(ChromeCommand::SetNetworkConditions(conditions.clone())).await?;
Ok(())
}
pub async fn execute_cdp(&self, cmd: &str) -> WebDriverResult<Value> {
self.execute_cdp_with_params(cmd, json!({})).await
}
pub async fn execute_cdp_with_params(
&self,
cmd: &str,
cmd_args: Value,
) -> WebDriverResult<Value> {
let v =
self.handle.cmd(ChromeCommand::ExecuteCdpCommand(cmd.to_string(), cmd_args)).await?;
v.value()
}
pub async fn get_sinks(&self) -> WebDriverResult<Value> {
let v = self.handle.cmd(ChromeCommand::GetSinks).await?;
v.value()
}
pub async fn get_issue_message(&self) -> WebDriverResult<Value> {
let v = self.handle.cmd(ChromeCommand::GetIssueMessage).await?;
v.value()
}
pub async fn set_sink_to_use(&self, sink_name: &str) -> WebDriverResult<()> {
self.handle.cmd(ChromeCommand::SetSinkToUse(sink_name.to_string())).await?;
Ok(())
}
pub async fn start_tab_mirroring(&self, sink_name: &str) -> WebDriverResult<()> {
self.handle.cmd(ChromeCommand::StartTabMirroring(sink_name.to_string())).await?;
Ok(())
}
pub async fn stop_casting(&self, sink_name: &str) -> WebDriverResult<()> {
self.handle.cmd(ChromeCommand::StopCasting(sink_name.to_string())).await?;
Ok(())
}
}