javamavenseleniumfirefoxselenium-webdriver

Selenium WebDriver possible to work without System.setProperty(path to driver)?


I using Java with Selenium WebDriver and I wondered is it possible to remover e.g.

System.setProperty("webdriver.gecko.driver", dirPath + "\\src\\test\\resources\\geckodriver.exe");

and swap this into import library to maven? I saw on mvnrepository this library

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>3.5.1</version>
</dependency>

and is it possible to remove System.setProperty and add this dependency?


Solution

  • You can check https://github.com/bonigarcia/webdrivermanager, which will do this part for you. For example:

    WebDriverManager.getInstance(ChromeDriver.class).setup();
    

    It'll download latest chromedriver into .m2 folder and automatically set required system property.