Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday 9 November 2017

"Geckodriver" execution issue while running Java application from Selenium Automation

You can get this issue most often while running Java application using Selenium IDE for automation testing. The issue look like this:

Exception in thread "main" java.lang.IllegalStateException: 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

The Selenium client bindings will try to locate the geckodriver executable from the system PATH. You will need to add the directory containing the executable to the system path.
  • On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
    export PATH=$PATH:/path/to/geckodriver
  • On Windows you need to update the Path system variable to add the full directory path to the executable. The principle is the same as on Unix.
All below configuration for launching latest firefox using any programming language binding is applicable for Selenium2 to enable Marionette explicitly. With Selenium 3.0 and later, you shouldn't need to do anything to use Marionette, as it's enabled by default.
To use Marionette in your tests you will need to update your desired capabilities to use it.
Java :
As exception is clearly saying you need to download latest geckodriver.exe from here and set downloaded geckodriver.exe path where it's exists in your computer as system property with with variable webdriver.gecko.driver before initiating marionette driver and launching firefox as below :-
//if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly through code
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");

//Now you can Initialize marionette driver to launch firefox
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(capabilities); 
And for Selenium3 use as :-
WebDriver driver = new FirefoxDriver();
Note : Just like the other drivers available to Selenium from other browser vendors, Mozilla has released now an executable that will run alongside the browser. Follow this for more details.

There is way to solve this issue

You are using latest version of Selenium WebDriver i.e. Selenium 3.x, this version of webdriver doesn't support direct firefox launch. You have to set the SystemProperty for webdriver.gecko.driver.
Replace the Code:-
WebDriver driver;
driver =new FirefoxDriver();
With This code:-
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>");
driver =new FirefoxDriver();
You can get the information about latest changes here
You can download the latest Gecko driver from here


No comments:

Post a Comment