Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping capabilities for initialization #44

Open
AminArria opened this issue Mar 14, 2019 · 7 comments
Open

Wrapping capabilities for initialization #44

AminArria opened this issue Mar 14, 2019 · 7 comments

Comments

@AminArria
Copy link

Hi I want to use with_capabilities to create a new client, but not sure if doing it right. This is what I'm doing:

extern crate tokio;
extern crate futures;
extern crate fantoccini;
extern crate webdriver;
extern crate serde_json;

use fantoccini::{Client, Locator};
use futures::future::Future;
use webdriver::capabilities::Capabilities;

fn main() {
    let mut cap = Capabilities::new();
    let arg = serde_json::from_str("{\"args\": [\"-headless\"]}").unwrap();
    cap.insert("moz:firefoxOptions".to_string(), arg);
    let c = Client::with_capabilities("http://localhost:4444", cap);
   
   // rest of the code down here...
}

If this is the right way to do it I was wondering if we could receive in the capabilities in another way that didn't involve me knowing about webdriver and serde_json and having to add them to my dependencies.

I'm open to making a PR if you prefer to discuss over actual code.

@jonhoo
Copy link
Owner

jonhoo commented Mar 14, 2019

You can construct the json::Value directly (rather than relying on from_str), but I agree with you it's pretty inconvenient. Part of the reason there isn't a better API is that the capabilities can take on different forms for different vendors, so I don't know of a good way to expose it beyond just serde_json::Value. This could perhaps be helped somewhat by fantoccini re-exporting serde_json::Value and webdriver::capabilities::Capabilities? Did you have a particular API in mind that you think would be better? I'd be happy to review a PR!

@AminArria
Copy link
Author

Re-exporting would be a sort of quick fix, but I don't know if its considered a good or bad practice. I would be inclined to go against it.

Ideally I would just change with_capabilities to receive something like a FancocciniCapabilities and then internally make it into a Capabilities.

@jonhoo
Copy link
Owner

jonhoo commented Mar 14, 2019

I'm inclined to re-export since we don't actually need our own wrapper functions or anything here. It's unclear what we gain from exposing our own. In your particular case, the maplit crate may be a good thing to look into too. Re-exporting that seems excessive though 🤔

@AminArria
Copy link
Author

AminArria commented Mar 15, 2019

Thanks for the idea of not using from_str, I changed it to:

let arg = json!({"args": ["-headless"]});

Yeah, re-exporting maplit might be a bit excessive. I'll make the PR to re-export the other libs.

@jonhoo
Copy link
Owner

jonhoo commented Mar 15, 2019

Ah, yes, I'd forgotten about json!. Maybe we do something like

pub mod ext {
    pub use serde_json::{json, Value};
    pub use webdriver::capabilities::Capabilities;
}

@GRVYDEV
Copy link

GRVYDEV commented Dec 21, 2019

Hi I want to use with_capabilities to create a new client, but not sure if doing it right. This is what I'm doing:

extern crate tokio;
extern crate futures;
extern crate fantoccini;
extern crate webdriver;
extern crate serde_json;

use fantoccini::{Client, Locator};
use futures::future::Future;
use webdriver::capabilities::Capabilities;

fn main() {
    let mut cap = Capabilities::new();
    let arg = serde_json::from_str("{\"args\": [\"-headless\"]}").unwrap();
    cap.insert("moz:firefoxOptions".to_string(), arg);
    let c = Client::with_capabilities("http://localhost:4444", cap);
   
   // rest of the code down here...
}

If this is the right way to do it I was wondering if we could receive in the capabilities in another way that didn't involve me knowing about webdriver and serde_json and having to add them to my dependencies.

I'm open to making a PR if you prefer to discuss over actual code.

Hi Amin,
Your reply was incredibly helpful to my understanding of adding capabilities but I am wondering where you found the "moz:firefoxOptions" string at. I am currently trying to replicate this but using Chromedriver and I haven't had much luck with it. Thank you for your time!

@AminArria
Copy link
Author

Hi @Grav3y sadly I didn't document where I got it, but this links might be useful

That project I never got to implementing the capabilities for a Chromedriver so not much else I can do to help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants