Dustin N. Dustin N. - 1 year ago 190
Java Question

Start Firefox ThreadLocal Driver In Selenium 3 - Java

I just updated to Selenium 3.0.0-beta3 and am trying to execute tests in Firefox 45.

I have downloaded v.10 of the geckodriver.exe and added that to my PATH environment variables. I am also setting the system property in the code for the geckodriver like I do when I use the Chrome driver, which works perfectly fine, however, I still end up with the following TestNG message:

org.openqa.selenium.WebDriverException: The path to the driver
executable must be set by the webdriver.gecko.driver system property;
for more information, see https://github.com/mozilla/geckodriver. The
latest version can be downloaded from
https://github.com/mozilla/geckodriver/releases Command duration or
timeout: 411 milliseconds Build info: version: '2.52.0', revision:
'4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11
11:22:43' System info: host: 'VMP-2316', ip: '', os.name:
'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version:
'1.8.0_92' Driver info: org.openqa.selenium.remote.RemoteWebDriver

Here is the code I am using to set the driver:

// Set Driver
threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities dc = new DesiredCapabilities();

System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");

dc.setCapability("marionette", true);

threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));

Answer Source

Another way would be to define the path of the driver in the command line launching the server/node:

java -Dwebdriver.gecko.driver=path/to/geckodriver.exe -jar selenium-server-standalone-3.0.0-beta3.jar
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download