Skip to content

Add an API to set capabilities #10

Open
@equalsraf

Description

@equalsraf

I don't have a very concrete example to propose for this yet. But we need some way to build the NewSessionCmd object that allows setting the capabilities and desired capabilities.

In #9 I took the cheap way out and just used the json! macro to craft the capabilities. But we need something that can be used in a public api like a builder for the capabilities object.

Storage can be implemented via a new type (this uses the code in #9 as an example)

#[derive(Serialize, Default)]
pub struct Capabilities {
    alwaysMatch: collections::BTreeMap<String, JsonValue>,
}

#[derive(Serialize)]
pub struct NewSessionCmd {
    capabilities: Capabilities,
}

impl NewSessionCmd {
    pub fn new() -> Self {
        let mut capabilities: Capabilities = Default::default();
        capabilities.alwaysMatch.insert("goog:chromeOptions".to_string(),
                                                                  json!({"w3c": true}));
        NewSessionCmd {
            capabilities,
        }
    }
}

Maybe something like the following method in NewSessionCmd but have not taken into consideration the firstMatch attribute in the spec. Probably should have a look at it first.

    pub fn capability(&mut self, name: &str, value: Option<JsonValue>) {
        match value {
            Some(value) => self.capabilities.alwaysMatch.insert(name.to_string(), value),
            None => self.capabilities.alwaysMatch.remove(name),
        };
    }

My other doubt here is the type of the supplied value argument. Should we take a serde_json::Value or more generically anything that implements Serialize? Since Value does implement Serialize maybe we should start with just Value.

TODO

  • add api/methods to NewSessionCmd to manipulate the capabilities
  • change DriverSession::create_session API to accept additional parameters?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions