WebDriverManager in Selenium

Generally in selenium, we set driver binary in our Automation scripts using below line..

  "System.setProperty(“webdriver.chrome.driver”, “//path//to//chromedriver”)"

To eliminates the problem of locally storing the driver binary files and maintaining different versions of the driver files  (for different browsers),
Automating the WebDriver binaries management by simply replace the above line in the your automation script with the below line:

        WebDriverManager.chromedriver().setup();  -- for chrome browser
WebDriverManager.firefoxdriver().setup();  -- for mozilla firefox browser
WebDriverManager.iedriver().setup();  -- for internet explorer browser

.....similalry for other browsers
WebDriverManager.operadriver().setup();
WebDriverManager.phantomjs().setup();
WebDriverManager.edgedriver().setup();

Note:  It downloads the required Driver binary file (if not present locally) into Cache (default location ~/.m2/repository/webdriver).


Using the WebDriverManager
@Test
    public void TestWDM()
    {
        //setup the chromedriver using WebDriverManager
        WebDriverManager.chromedriver().setup();

        //Create driver object for Chrome
        WebDriver driver = new ChromeDriver();

        //Navigate to a URL
        driver.get("https://www.google.com/");

        //quit the browser
        driver.quit();
    }


Setup required in your project :

You can this as Maven dependency r gradle dependency to set the

Adding WebDriverManager as Maven dependency?
*******************************************************
<dependencies>
  <dependency>
  <groupId>io.github.bonigarcia</groupId>
  <artifactId>webdrivermanager</artifactId>
  <version>3.4.0</version>
  </dependency>
  </dependencies>
*******************************************************
Adding WebDriverManager as Gradle dependency:

*******************************************************
dependencies {
  testCompile("io.github.bonigarcia:webdrivermanager:3.0.0")
}
*******************************************************


Once the dependency is sorted in your Maven/Gradle project, add the below import in your Java file.
import io.github.bonigarcia.wdm.WebDriverManager;


Other capabilities of webdrivermanager:

1. start specific version of browser’s driver
2. specify platform (32-bit or 64-bit)
3. set proxy, username and password

like below:
WebDriverManager.chromedriver()
                 .version("2.40") 
                 .arch32()
                 .proxy("myproxyhostname:80")
                 .proxyUser("myusername")
                 .proxyPass("myawesomePassword")
.setup();



Hope this is helpful... Thanks!!