WebDriverManager in Selenium
Always gives a sigh of relief, right?
I will tell you why I said so. What is WebDriverManager and what does it do? Let’s jump right into it!
WebDriverManager is an API that grants users the freedom of handling the driver executable like chromedriver, geckodriver etc in a fully automated manner.
Life before WebDriverManager
Before starting to automate the web application we need to download the driver executable manually for the required browsers like chrome, firefox, etc.
Then, after downloading the executable into our local system, we need to set the path.
It is important to verify the version of the browser all the time and keep updating, else it will not work.
In addition to all these points, each different operating system, be it Windows, MacOS, Linux, BSD etc. has a unique or separate method to obtain those drivers, which makes it quite a hassle to manage over hybrid systems.
This is the traditional method for setting up browser path bellow:
//For Chrome Browser System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver.exe"); //For Firefox Browser System.setProperty("webdriver.gecko.driver", "./Drivers/geckodriver.exe");
Tedious? Lots of manual stuff? NO WORRIES!
WebDriverManager makes it easy and convert the manual stuff into automation.
It verifies the version of the browser(eg chrome, firefox, Edge etc.) installed in your local machine by its own.
It also uses the latest version of the driver(chromedriver, geckodriver etc.) regardless which version of driver installed in your machine.
Instantiate a browser using WebDriverManager in Selenium Java:
Add this dependency to pom.xml in your project. Don't forget to save it.
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager --> <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>5.2.3</version> </dependency>
This is the time to get rid of all the above manual stuff. You can replace the
This is the time to get rid of all the above manual stuff. You can replace the code form “system.setProperty()” call to " WebDriverManager.Xdriver().setup();"
It resolves compatibility issues of the driver binaries for all the browsers.
Several drivers managers for different browsers are provided by WebDriverManager.
As follows :
WebDriverManager.chromedriver().setup(); WebDriverManager.firefoxdriver().setup(); WebDriverManager.edgedriver().setup(); WebDriverManager.operadriver().setup(); WebDriverManager.chromiumdriver().setup();
Sample selenium project with browser setup
Instantiate a browser using WebDriver-Manager in Selenium Python:
WebDriver-Manager is a free opensource library which can smartly handle all the hazardous methods of using traditional way in Python as well.
Prerequisites: Make sure Selenium is installed.( Else,run in command -pip install selenium)
Next step -install webdriver-manager by running the following command
pip install webdriver-manager
It is advisable to verify whether selenium and webdriver-manager are installed by running the following command
For Chrome Browser, use :
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install())
For Firefox Browser, use :
from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
WebDriverManager is a true friend to automation. It saves time, eliminates a lot of tedious manual work, helps in resolving incompatibility issues to make Selenium Automation easier and interesting. Happy testing.