thirtyfour/extensions/addons/firefox/
firefoxcommand.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use fantoccini::wd::WebDriverCompatibleCommand;
use http::Method;
use serde_json::json;
use url::{ParseError, Url};

#[derive(Debug)]
pub enum FirefoxCommand {
    InstallAddon {
        path: String,
        temporary: Option<bool>,
    },
    FullScreenshot {},
}

impl WebDriverCompatibleCommand for FirefoxCommand {
    fn endpoint(&self, base_url: &Url, session_id: Option<&str>) -> Result<Url, ParseError> {
        let base = { base_url.join(&format!("session/{}/", session_id.as_ref().unwrap()))? };
        match &self {
            FirefoxCommand::InstallAddon {
                ..
            } => base.join("moz/addon/install"),
            FirefoxCommand::FullScreenshot {} => base.join("moz/screenshot/full"),
        }
    }

    fn method_and_body(&self, _request_url: &Url) -> (Method, Option<String>) {
        match &self {
            FirefoxCommand::InstallAddon {
                path,
                temporary,
            } => (Method::POST, Some(json!({"path": path, "temporary": temporary}).to_string())),
            FirefoxCommand::FullScreenshot {} => (Method::GET, None),
        }
    }
}