What is Browser Binary Manager how to use it for Selenium

前端 未结 2 437
借酒劲吻你
借酒劲吻你 2021-01-25 13:06

I came to know recently that using \'WebDriver Binaries\' manager is a good practice in Automation projects. But not sure what is this and how to use? Did some google searches

相关标签:
2条回答
  • 2021-01-25 13:48

    When you say WebDriver binaries, I am assuming that you are talking about the WebDriver bindings or the libraries. With out adding the WebDriver binding's into your project you can't really do anything with the WebDriver interface, like you can't invoke any browser or drive any website. Either you can manually add them into your project build path or you can use any dependency management tool like Maven for getting all the WebDriver libraries into your project. You can then use them. You can either just add the standalone server file, which would do the same job as WebdDriver bindings.

    There are Third Party Driver's which we use for each of the bowser's like, chrome - chromedriver.exe, firefox - geckodriver.exe ..etc ---These are also called as WebDriver binarie's(mostly refereed as driver files).

    0 讨论(0)
  • 2021-01-25 13:49

    Finally Got to know about it some time back as below, thought it might be useful for other hence posting it as self Answer.

    As an automation engineer, we always have to set the path for the browser binary, for this first, we need to download a binary file[driver.exe] which allows WebDriver to handle browsers. In addition, the absolute path to this binary must be set as JVM properties, as follows:

    System.setProperty("webdriver.chrome.driver", "Your path to/chromedriver"); System.setProperty("webdriver.gecko.driver", "Your path/geckodriver");

    Its just not about the downloading and setting properties to set the binary path but you also need to change the binaries frequently as the browser version or Selenium version changes. I found this solution and implemented it- and That's All! Now I don't need exe libraries anymore for the browsers! A small maven repository made life easy.

    How it works: When working on a Maven project, you just need to add a dependency called WebDriverManager. This library will take care of everything your browser version and driver.

    In order to use WebDriverManager in a Maven project, you just need to add the following dependency in your pom.xml:

    <dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.3.0</version>
    </dependency>
    

    WebDriverManager actually gets your browser version and downloads the compatible browser binary by itself to make you run your code without interruption.

    Now, rather than setting the browser binaries, you just need to add below line of code in your browser manager class and that's it.

    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    

    You're done! The line WebDriverManager.chromedriver().setup(), does all magic for you:

    It checks for the latest version of the WebDriver binary.

    It downloads the WebDriver binary if it's not present on your system.

    It exports the required WebDriver Java environment variables needed by Selenium.

    Reference: https://github.com/bonigarcia/webdrivermanager#webdrivermanager-as-java-dependency

    0 讨论(0)
提交回复
热议问题