Aly Magdy Aly Magdy - 3 months ago 40
Java Question

Exception in thread "main" java.lang.IllegalStateException

I am studying automation testing tutorial by selenium and was writing my first script in java language and have got that message in "Console" at Eclipse.

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
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:91)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:245)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:220)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:215)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
at automationFramework.FirstTestCase.main(FirstTestCase.java:12)


My Code :

package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {

public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub

// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();

//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");

// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");

//Wait for 5 Sec
Thread.sleep(5);

// Close the driver
driver.quit();
}

}


The Tutorial Link :
http://toolsqa.wpengine.com/selenium-webdriver/first-test-case/

Answer

This is because Selenium 3 uses a seperate driver to interact with the Firefox browser.

Check out this link.

Add the path of geckodriver.exe with System.setProperty. Assuming path C:\Selenium\Firefox driver\geckodriver.exe:

System.setProperty("webdriver.gecko.driver","C:\Selenium\Firefox driver\geckodriver.exe");
WebDriver driver = new FirefoxDriver();