Time to say ‘Good Bye’ to traditional way of instantiating browsers in Selenium?

Jayakrishnan Kunnath
2 min readSep 25, 2021

--

We know that to execute Selenium automation scripts on browsers like chrome or firefox, we must download the binary files of these drivers like chromedriver and geckodriver, etc. After this, we need to set the path to these binaries in the automation script or add the classpath location.

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

Issues with traditional approach

  1. If the binary file and browser version mismatch causes error
  2. Each time we have to upgrade binary according to browser versions
  3. File path to be provided and it consume space in the project

Bonigarcia WebDriverManager

A library and WebDriverManager does magic for you:

  1. It checks the version of the browser installed in your machine (e.g. Chrome, Firefox).
  2. It checks the version of the driver (e.g. chromedriver, geckodriver). If unknown, it uses the latest version of the driver.
  3. It downloads the WebDriver binary if it is not present on the WebDriverManager cache (~/.m2/repository/webdriver by default).
  4. It exports the proper WebDriver Java environment variables required by Selenium (not done when using WebDriverManager from the CLI or as a Server).

How to instantiate a browser using WebDriverManager in Selenium?

WebDriverManager resolves the driver binaries for the browsers Chrome, Firefox, Edge, Opera, PhantomJS, Internet Explorer, and Chromium. For that, it provides several drivers managers for these browsers. These drivers managers can be used as follows:

WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.phantomjs().setup();
WebDriverManager.iedriver().setup();
WebDriverManager.chromiumdriver().setup();

When we setup WebDriverManager in Project. By default, it downloads the latest version for a specified driver executable/s. Using WebDriverManager, we can also setup driver executable/s for a specific browser version.

//Code Snippet for Chrome Browser
WebDriverManager.chromedriver().version("2.40")

Maven dependency:

Here is the maven dependency for WebdriverManager.

Maven dependency

https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager

All right! Its time to move on with Webdriver Manager.!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response