Vrtgs/thirtyfour

Feature: Create WebDriverManager for starting and stopping local webdriver servers (and more)

Opened this issue ยท 11 comments

fn run_chromedriver(path: String) -> std::process::Child{
    let output = 
        std::process::Command::new(&path)
        .arg("--ip=localhost")
        .arg("--port=4444")
        .spawn()
        .expect("Command failed");
    return output
}

I'm using this function to start chromedriver, passing a path to it as parameter, but if you have use other selenium bindings, this is the common use. Pass the ip address for webdriver force the user to start by command line the chromedriver executable for example.
I'm calling the above function this way:

let mut chromedriver = run_chromedriver(String::from("./34_drivers/chromedriver"));

and the latest lines are:

    driver.quit().await?;
    chromedriver.kill().expect("chromedriver server process not killed, do manually"); 
    Ok(())

I'm doing it because driver.quit() don't kill the session and chromedriver process still running after program has finished. Sometimes, the browser doesn't open, and the prompt say the output of chromedriver executable (chromedriver was started successfully whatever) and the next lines to exit never are executed, so the program run forever doing nothing, like stucked in while loop.

I'm not clear on what the issue is here.

  1. Are you suggesting that this library should take care of starting and stopping the chromedriver binary? What about other browsers?
  2. Or are you referring to the issue of the WebDriver session not being stopped correctly?

As for (1), this has not been a goal of this project so far, but I can see how it could be useful especially for running on your local machine during development. However, one issue with running chromedriver locally like this is that the browser will steal keyboard input focus depending on what you do, and will also be brought in front of other applications if you take a screenshot via automation, which isn't ideal if you want to keep working while the browser is running. I would strongly recommend using docker to run the browser, as per the README. You can view the browser in-flight using VNC.
If you do want thirtyfour to manage its own chromedriver instance, let me know. That would transform this ticket into a feature request, and we can discuss how that feature should work in the case of chromedriver and geckodriver. I would be happy to limit support to just those two.

For (2), this would be a bug if driver.quit().await did indeed not close the session. I will test this further to confirm.
Btw, closing the WebDriver session will not terminate chromedriver itself. That is not what that API call does.

I never thought of making it automatically download the latest version of chromedriver or geckodriver. I like that idea.

I've updated this issue to be for the following features:

  • Create WebDriverManager to manage local webdriver servers (start, stop, etc)
  • Automatically download latest chromedriver or geckodriver if not present
  • Option to automatically update to the latest chromedriver or geckodriver if the current one is outdated

The webdriver download parts may be split out into a separate issue.

For reference: https://pypi.org/project/webdriver-manager/
Something like this would be cool.

Also, I think this should probably be a separate crate+repo since it would be useful for fantoccini as well.

@stevepryde may it help you?
https://crates.io/crates/webdriver-install
The feature indeed would be nice to have!

Definitely!

There's another aspect which is managing the life cycle of the webdriver etc.

Thanks for letting me know about this ๐Ÿ˜Š

See also #127

For now I would direct people to use Selenium Manager. It can be used as a lib crate.
https://github.com/SeleniumHQ/selenium/tree/trunk/rust

Also see: https://github.com/stevepryde/thirtyfour#using-selenium-manager

@stevepryde I noticed that your second link isn't in the readme anymore. Do you still recommend using Selenium Manager or is there a better way? I've been struggling with this myself, and am using a naive implementation in the meantime (link).

At this stage I still have not actually used Selenium-manager because it's not easy to build and to my knowledge the binaries are not hosted anywhere. I had planned to maintain a mirror of it that gets pushed to crates.io but that might be more work than I have time for.

The advantage is that it's an official tool so it should be well supported, hopefully.

That said, it isn't practical to use. I prefer using the Selenium docker images personally.