Coder Social home page Coder Social logo

Comments (4)

stevepryde avatar stevepryde commented on July 21, 2024

If I understand correctly, the issue you have is that you want to run more than 5 parallel sessions of Chrome.

There are some ways you can do this without any changes to thirtyfour:

  1. Use selenium server (standalone or grid) rather than using chromedriver directly. Selenium will take care of running parallel sessions for you.
  2. Use my Xenon project (which can possibly replace selenium for simple use cases) - however it is in very early stages and definitely not ready for production use.

As for your requests. It is pretty trivial to make WebDriverSession public. However I am still not sure why you need this or how it would help to get more parallel sessions working. It seems more likely this would be misleading for most users, and I want to understand your use case before making any changes here.

Likewise with allowing GenericWebDriver to reuse existing connections. Which connections are you referring to?
GenericWebDriver doesn't really know anything about connections. All it knows is that it has a conn instance that has a create and an execute method. The actual HTTP connection to selenium or webdriver server is managed in ReqwestDriverAsync or SurfDriverAsync etc. There really is no persistent "connection" as such. The HTTP client object is reused (for reqwest anyway) but each request to selenium/webdriver is a separate REST request.

I'm happy to elaborate on how these are wired up if you need. The documentation around how everything is wired together is pretty sparse at the moment and it would be good to know which parts need to be expanded.

I am also not sure what you mean by "implementing their own WebDrivers". The only reason I can see to implement your own WebDriver struct is to use a different HTTP client. If you are happy with reqwest (using tokio) or surf (using async-std) then you don't need to do this.

GenericWebDriver is generic over the HTTP client implementation, not generic over WebDriver. The actual WebDriver structs are defined already such as

pub type WebDriver = GenericWebDriver<ReqwestDriverAsync>;

(in src/webdriver.rs)

The WebDriverSession struct is really just an implementation detail that allows WebElement and related structs to have a reference to the underlying HTTP client and its machinery, so that you can do things like find element from element, and also execute scripts on a particular element (e.g. elem.scroll_into_view())

Please provide more detail about what you are trying to do, and I'll see if I can help. Thanks.

from thirtyfour.

hrvolapeter avatar hrvolapeter commented on July 21, 2024

Using selenium for my use case feel like a heavyweight I like to interact with WebDriver directly. Chromedriver has limit of 7 simulations TCP connections (some of them might not be usable directly). However one TCP connection can be used for multiple sessions. Unfortunately the GenericWebdriver always creates a new Reqwest client which initialises a new TCP connection.

I've implemented my own version of WebDriver struct where the final result looks like:

 pub async fn new<C>(
        conn: Arc<dyn RemoteConnectionAsync>,
        capabilities: C,
    ) -> WebDriverResult<Self>
    where
        C: Serialize,
    {
        let (session_id, session_capabilities) = start_session(conn.clone(), capabilities).await?;

where you can pass existing request client (which maintains connection pool) when creating a new instance of WebDriver, in my case it's just specific type for reqwest client. Unfortunately to do this I had to fork thirtyfour and make the WebDriverSession interface public.

Alternative could be to provide another new_with_client method to generic WebDriver where you could pass already existing client to the WebDriver.

Of course you could try to implement your own struct with RemoteConnectionAsync + RemoteConnectionAsyncCreate interfaces however since the WebDriver uses the create function on a generic type internal state cannot be persisted you can go for mut static to persist the state for the client pool but that sound unnecessarily hacky.

from thirtyfour.

stevepryde avatar stevepryde commented on July 21, 2024

Thanks for the explanation. I think I have a better idea of what you are trying to do now. It seems very specific to chromedriver (as it is currently implemented) because other webdrivers do not support multiple sessions this way.

I've made the WebDriverSession struct public in v0.13.3. Hopefully that will do what you need.

If you do want to do this using other webdrivers or with more than 7 connections, please do check out my Xenon project.
https://github.com/stevepryde/xenon

I agree that Selenium is more resource-hungry than necessary which is why I created Xenon. It essentially just proxies one or more webdriver sessions through a centralised hub which I assume is similar to what Selenium does, but without using nearly as much cpu or memory. For running multiple sessions via a single chromedriver instance or even multiple sessions with multiple chromedriver instances, Xenon should handle that just fine. I have run the thirtyfour test suite through it several times and that works. Now if only there was a way to get chrome itself to use less cpu and memory, that would be nice.

from thirtyfour.

hrvolapeter avatar hrvolapeter commented on July 21, 2024

Thank you @stevepryde looks good to me 👍

from thirtyfour.

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.