selenium 2 chrome driver
Add WebDriverManager to your project:
<dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>5.0.1</version></dependency>
This library downloads the latest version of the WebDriver binary you need and export the proper Java system variable (webdriver.chrome.driver
, webdriver.gecko.driver
, webdriver.opera.driver
, webdriver.edge.driver
, webdriver.ie.driver
), simply using one of the following sentences respectively:
WebDriverManager.chromedriver().setup();WebDriverManager.firefoxdriver().setup();WebDriverManager.operadriver().setup();WebDriverManager.edgedriver().setup();WebDriverManager.iedriver().setup();
More info on https://bonigarcia.dev/webdrivermanager/
I am not sure about Maven but this how I set the property webdriver.chrome.driver
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");WebDriver driver = new ChromeDriver();driver.get("http://www.google.com");
Setting the webdriver.chrome.driver
system property via maven can be done by the following (and tested working):
Add
systemPropertyVariables
configuration to themaven-surefire-plugin
in yourpom.xml
. This is (typically) becausesurefire
is the caller for tests and where system properties will be set.<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.7.1</version> <configuration> <systemPropertyVariables> <webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver> </systemPropertyVariables> </configuration></plugin>
Now define
${webdriver.chrome}
somewhere. A good start is a<properties>
section in yourpom.xml
<properties> <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome></properties>
Potentially this could be done better via the use of <profiles>
like in Simon Martinelli's example