use std::path::Path;
use std::sync::Arc;
use base64::Engine;
use base64::prelude::BASE64_STANDARD;
use super::FirefoxCommand;
use crate::error::WebDriverResult;
use crate::session::handle::SessionHandle;
use crate::support;
#[derive(Debug, Clone)]
pub struct FirefoxTools {
pub handle: Arc<SessionHandle>,
}
impl FirefoxTools {
pub fn new(handle: Arc<SessionHandle>) -> Self {
Self {
handle,
}
}
pub async fn install_addon(&self, path: &str, temporary: Option<bool>) -> WebDriverResult<()> {
self.handle
.cmd(FirefoxCommand::InstallAddon {
path: path.to_string(),
temporary,
})
.await?;
Ok(())
}
pub async fn full_screenshot_as_png(&self) -> WebDriverResult<Vec<u8>> {
let r = self.handle.cmd(FirefoxCommand::FullScreenshot {}).await?;
let encoded: String = r.value()?;
Ok(BASE64_STANDARD.decode(encoded)?)
}
pub async fn full_screenshot(&self, path: &Path) -> WebDriverResult<()> {
let png = self.full_screenshot_as_png().await?;
support::write_file(path, png).await?;
Ok(())
}
}