selenium 2 chrome driver selenium 2 chrome driver selenium selenium

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):

  1. Add systemPropertyVariables configuration to the maven-surefire-plugin in your pom.xml. This is (typically) because surefire 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>
  2. Now define ${webdriver.chrome} somewhere. A good start is a <properties> section in your pom.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