Make Selenium Easy

WebDriverManager – Get Rid Of Compatability Issues Between Browser And Drivers

Introduction

While automating a Web-based application using Selenium WebDriver, we must have faced the below issues:-

  1. Unable to create session due to outdated browser driver executable.
  2. maintaining the same browser version across the team so that your framework can run scripts.
  3. compatibility issues between currently installed browser and available driver executable in the framework
  4. managing browsers on the different operating system

Earlier I remember that we used to disable auto-update of browser to make our scripts stable. Nowadays browsers keep updating and we can not restrict our application to run on a specific version of the browser.

All these issues we can solve using a library called WebDriverManager and focus more on covering functionalities rather than spending much time on these browser’s compatibilities issues.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

What is WebDriverManager?

In Selenium WebDriver, you might aware that you need to explicitly download the compatible browser’s driver executable binary file and set the JVM path or properties so that selenium commands can be executed. These browser driver executables work as a bridge between your selenium commands/codes and browser. Below lines of code will explain more about the above statement.

We can auto manage the download of browser executable and setting up of path using WebDriverManager.

How to use it?

WebDriverManager is a Java library. So you can either download it or use it as a dependency in a Maven or Gradle project. I will use the latest maven dependency of WebDriverManager as below:-

After adding the above dependency, you just need to replace System.setProperty() line as below.

If you want to launch chrome browser then use the below line of code –

WebDriverManager.chromedriver().setup();

A similar line of code for other browsers.

The above code from WebDriverManager does magic for you:-

  1. It checks the version of the browser installed in your machine (e.g. Chrome, Firefox).
  2. It matches the version of the driver (e.g. chromedrivergeckodriver). If unknown, it uses the latest version of the driver.
  3. It downloads the driver if it is not present on the WebDriverManager cache (~/.cache/selenium by default).
  4. It exports the proper WebDriver Java environment variables required by Selenium.

In short, it downloads the compatible browser driver executable as per the currently installed browser on your system and stores it on your local itself and an environment path is set up.

Example Code

Output

Observer above output. It has download chromedriver 91.0.4472.101 after checking the installed version of chrome on my system. The below images will change in the future based on newer versions. This is the magic done by WebDriverManager.

It will download only if the compatible browser executable is not available in the cache. You can see in the above output how well organized it keeps the chromedrivers.

You can clone the git repo consisting above examples from here.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

WebDriverManager – Get Rid Of Compatability Issues Between Browser And Drivers

by Amod Mahajan time to read: 3 min
0
%d bloggers like this: