Code Monkey home page Code Monkey logo

Comments (7)

AminArria avatar AminArria commented on May 28, 2024 1

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.

from fantoccini.

jonhoo avatar jonhoo commented on May 28, 2024 1

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;
}

from fantoccini.

jonhoo avatar jonhoo commented on May 28, 2024

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!

from fantoccini.

AminArria avatar AminArria commented on May 28, 2024

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.

from fantoccini.

jonhoo avatar jonhoo commented on May 28, 2024

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 🤔

from fantoccini.

GRVYDEV avatar GRVYDEV commented on May 28, 2024

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!

from fantoccini.

AminArria avatar AminArria commented on May 28, 2024

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

from fantoccini.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.