DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. WebDriverManager: A Hassle-Free Browser Binary Manager for Selenium

WebDriverManager: A Hassle-Free Browser Binary Manager for Selenium

Learn how to use WebDriverManager to manage binary paths in Selenium.

Nishil Patel user avatar by
Nishil Patel
·
Dec. 03, 18 · Tutorial
Like (5)
Save
Tweet
Share
15.17K Views

Join the DZone community and get the full member experience.

Join For Free

As an automation engineer, I believe you always have to set the path for the browser binary. You know that in order to use some browsers such as Chrome, Firefox, Opera, PhantomJS, Microsoft Edge, or Internet Explorer, first, you need to download a binary file 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", "path/to/chromedriver");
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver");
System.setProperty("webdriver.ie.driver", "path/to/IEDriverServer.exe");

It's annoying every time you need to set the binary path. It's not just limited to this one; you also need to change the binaries frequently as the browser version or Selenium version changes. In one major long-term project, the client asked me why he needed to change the library. What if he didn't need to change the library and the script worked as-is even if he changed the browser versions? I was speechless, but later, doing R&D, I found a lifesaver solution. I implemented it, and bingo! I didn't need exe libraries anymore for the browsers! A small maven repository saved the day.

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 need to add the following dependency in your pom.xml (Java 7 or upper required):

<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.4</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 and you're done.

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

The line WebDriverManager.chromedriver().setup(); WebDriverManager does 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.

For each and every browser you can add setup the particular WebDriverManager instance.

  1. More benefits of the WebDriver: You can also search for the particular binary version as well in the WebDriverManager. By default, it'll download the latest binary version.
  2. You can also set the path for the downloaded binary files if in case future use.
  3. By default, WebDriverManager connects to the specific driver repository URL to find out what is the latest version of the binary. This can be avoided forcing to use the latest version from the local repository.
  4. By default, WebDriverManager finds out the latest version of the binary, and then it uses the cached version if exists. This option forces to download again the binary even if it has been previously cached.
  5. By default, WebDriverManager skips beta versions. With this method, WebDriverManager will download also beta versions.
  6. By default, WebDriverManager would try to use the proper binary for the platform running the test case (i.e. 32-bit or 64-bit). This behavior can be changed by forcing a given architecture: 32-bits (Architecture.x32) or 64-bits (Architecture.x64);

Now the struggle of checking compatible binaries ends. You can certainly enjoy  hassle-free automation and make the client happy.

32-bit Download Library Test case 64-bit Binary file IT Repository (version control) Apache Maven

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Validate Three Common Document Types in Python
  • Top 5 Node.js REST API Frameworks
  • Best Practices for Writing Clean and Maintainable Code
  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: