Selenium Manager is a new tool that helps to get a working environment to run Selenium without having worried about setting path or adding another extra driver manager plugin. With latest version 4.6, Selenium Manager will configure the required browser drivers for Chrome, Firefox, and Edge if they are not present on the PATH.
To run your Selenium test with Selenium 4.6, you only need to required browsers to be installed on your environment. If you already have browser drivers installed or using plugin, this new feature will be ignored. If you’d like to help us test it, though, delete your drivers or remove your driver manager plug-in and run it. You should be all Good.
Lets us how we use to add path earlier and how to use Selenium Manager
In the beginning until we found Webdriver manager, we use to set path for the driver like below
System.out.println("launching chrome browser"); System.setProperty("webdriver.chrome.driver", driverPath+"chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.navigate().to("http://demo.seleniumeasy.com");
If we don't set the path like above, script will fail with an error message like the below one:
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://chromedriver.chromium.org/. The latest version can be downloaded from https://chromedriver.chromium.org/downloads
Third party plugin 'WebDriverManager' by Boni Garcia
And later we started using WebDriverManager plugin by Boni Garcia. Webdrivermanager helps us to download and manage binaries/executables in an automated way.
We just need to add its dependency through Maven or Gradle to download all the necessary browser drivers. It will download version based on browser version installed (WebdriverManager discovers the version of a given browser in the different operating systems using command database), also ONLY if they are not present on the WebDriverManager cache (~/.m2/repository/webdriver by default).
In Maven project, we need to add the following dependency in pom.xml :-
<dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>5.1.1</version> <scope>test</scope> </dependency>
WebDriverManager provides a set of managers for Chrome, Firefox, Edge, Opera, Chromium, and Internet Explorer. The basic use of these managers is the following:
WebDriverManager.chromedriver().setup(); WebDriverManager.firefoxdriver().setup(); WebDriverManager.edgedriver().setup(); WebDriverManager.operadriver().setup(); WebDriverManager.chromiumdriver().setup() WebDriverManager.iedriver().setup();
The following example shows to launch Chrome browser using WebDriverManager.
System.out.println("Launching google chrome with new profile.."); WebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver();
Now to launch chrome browser With version Selenium latest version v4.6, we just need to add one line, No third part plug-in required / no path settings needed.
First we need pull latest version of selenium using maven / gradle which ever you are using currently -
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.6.0</version> </dependency>
On adding the below code for chrome browser, you can see the browser launched successfully. Similarly you can also try to launch other browsers as well.
System.out.println("Launching google chrome.."); WebDriver driver = new ChromeDriver();
Please leave your questions/comments/feedback below, we are happy to answer.
- ‹ Waits and Timeout in Selenium 4
- [node:title] ›