Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we add drivers in selenium as maven depandancies

Can we add gecko driver , ie driver or chrome driver as depandancy in POM? I tried to search but was not able to fine them on https://mvnrepository.com/artifact. Any reason why they are not placed on the maven repository ?

like image 786
Akash Chavan Avatar asked Jan 03 '23 08:01

Akash Chavan


1 Answers

As few comments mentioned, that driver are executable binary files. Maven cannot help you with that as it's just a dependency repository. Currently to run selenium for example on firefox we need to write :

System.setProperty("webdriver.gecko.driver", "driverpath/.exe");
WebDriver driver = new FirefoxDriver();

However we have new solution that will make us get rid if the first line of code and you won't need to download the dirver binary files anymore. Its called WebDriverManager and it's a dependency that can be added using Maven pom file. This will call the driver during run time with the latest version number. All you need to write now is :

WebDriverManager.firefoxdriver().setup();
WebDriver driver = new FirefoxDriver();

and you need to add this dependency in the pom file

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>2.2.1</version>
</dependency>

For more information about this please go to Github link to check all the rest of the driver like chrome , ie , etc.. WebDriverManagerLink

like image 145
mbn217 Avatar answered Feb 12 '23 13:02

mbn217