0

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?

Mateusz Sobczak
  • 1,551
  • 8
  • 33
  • 67
  • 1
    You may want to take a look at https://stackoverflow.com/questions/35285698/why-do-we-need-to-set-the-system-property-for-chrome-and-ie-browser-and-not-for – Nerzid Aug 22 '17 at 08:03

1 Answers1

5

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.

Serhii Korol
  • 843
  • 7
  • 15
  • As long as I remember, this is not supported anymore. Selenium forces you to set your driver path. – Nerzid Aug 22 '17 at 08:06
  • @Nerzid what do you mean by "not supported"? `WebDriverManager` does the same thing implicitly. Chrome property: https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/resources/webdrivermanager.properties#L10 Value retrieval: https://github.com/bonigarcia/webdrivermanager/blob/a697a9982c1157d76fe9c89db8e6912e4c3cbe9c/src/main/java/io/github/bonigarcia/wdm/ChromeDriverManager.java#L52 Property setter: https://github.com/bonigarcia/webdrivermanager/blob/a697a9982c1157d76fe9c89db8e6912e4c3cbe9c/src/main/java/io/github/bonigarcia/wdm/BrowserManager.java#L733 – Serhii Korol Aug 22 '17 at 08:25
  • Thanks it's work properly. I have one more question do you know why I must set OperaOptions op = new OperaOptions(); op.setBinary(new File("C:\\Program Files\\Opera\\47.0.2631.55\\opera.exe")); without it opera doesn't work? – Mateusz Sobczak Aug 22 '17 at 08:49
  • @MateuszSobczak see https://github.com/operasoftware/operachromiumdriver/issues/9 – Serhii Korol Aug 22 '17 at 09:04
  • @SergeyKorol For linux system should I set some parameter? – Mateusz Sobczak Aug 24 '17 at 08:47
  • @MateuszSobczak not sure what parameter do you mean. Could you clarify your question? – Serhii Korol Aug 24 '17 at 13:15