WebDriverManager Class in Selenium
Anwar Hasan Shuvo
Principal Software QA Engineer at Enosis Solutions | Test Automation | Selenium | Java | Postman | Maven | Manual Testing | BackEnd Testing
Browser drivers, such as chromedriver.exe for Chrome or geckodriver.exe for Mozilla, are required to run Java-Selenium scripts.
We need to download those drivers and set the path in the script manually. Sometimes, when the browser version doesn’t match with the downloaded drivers, automation scripts can not be run. It is quite cumbersome to download manually and manage these browser drivers by checking current browsers.
WebDriverManager class in Selenium allows to automatically download driver binaries without having to set up path in scripts.
Hence, It should be downloaded in any directory, and WebDriverManager downloads the driver to a local cache.
However, we can set the path in scripts where the driver will be downloaded. This task can be accomplished using the following lines of codes.
Maven Dependency for WebDriverManager:
<dependencies>
<dependency>
? ? <groupId>io.github.bonigarcia</groupId>
? ? <artifactId>webdrivermanager</artifactId>
? ? <version>5.1.1</version>
</dependency>
</dependencies>
Chrome Code Snippet for WebDriverManager:
import io.github.bonigarcia.wdm.WebDriverManager;
WebDriverManager webDriverManager;
webDriverManager = WebDriverManager.chromedriver();
webDriverManager.config().setCachePath("Path Location"); //Provide the path where you want to download the driver
webDriverManager.setup();
I hope you found this post to be beneficial. Thanks!
Software Engineer | Django, FastAPI | Go | AWS | Docker, Kubernetes | 5+ years experience
2 年Good work brother!
Senior Software Developer in Test | Selenium | API | Backend Automation | Jenkins | AWS SAA-CO2 | DevOps
2 年Well done Shuvo.
Sr. Software Quality Assurance Engineer at SELISE Digital Platforms | QA Automation Engineer
2 年Great Work bhai