Click here to Skip to main content
15,891,529 members
Articles / WebDriver
Tip/Trick

Selenium 3 using Firefox Geckodriver

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
28 Feb 2017CPOL2 min read 12.1K  
Run test scripts on Firefox browser using Selenium 3 with GeckoDriver

Introduction

To run tests on Firefox browser with Selenium 3, we need Geckodriver executable unlike selenium 2 where Firefox browser was default for selenium.

Background

Until Selenium 3 released to the market, Firefox browser was the default browser which doesn't need any executable to be set. But later as the Firefox internals changed from version 48 and Marionette (the next generation of FirefoxDriver) is turned on by default for Selenium 3.

Find more information, see how Marionette works.

So whenever we run tests using selenium 3 on Firefox v48 and later, Selenium client bindings will try to locate the geckodriver executable from the system path.

Using the Code

If you have worked with other browsers like Chrome and Internet Explorer, we will be adding an executable path of the driver server. In the same way, we now need to add for Firefox browser.

If we try to run the program without adding geckodriver executable path, it will throw runtime exception as "java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;" in which it clearly says that we need to set geckodriver system path.

Below is the syntax to set path for geckodriver executable:

Java
String driverPath = "<path to gecko driver executable>";
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe"); 
driver = new FirefoxDriver();

Using selenium, we can also execute tests on Remote machine by defining desired capabities. Now to run tests on remote machine on Firefox Browser, we need to set capability for marionette.

Java
String driverPath = "<path to gecko driver executable>";
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe"); 
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true); 
WebDriver driver = new FirefoxDriver(capabilities);

From Where Can You Download GeckoDriver Executable?

Please find the GeckoDriver Downloads here. Make sure you download the appropriate version and try to have the latest version always.

What to Know More on GeckoDriver?

Check out the official Github page of GeckoDriver.

Is Geckodriver Stable Now?

Currently, they are still working on few things like Actions API, which is not yet fully implemented in Marionette. So right now, may be it is not good to go and implement in your framework.

You can see the issues which they are currently working on.

If you have any issues working on Geckodriver, please go through this link on Launching firefox browser using Geckodriver Selenium 3 which has many issues listed with solutions.

Hope this helps you to set up and run your tests using Geckodriver on Firefox browser.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Tester / Quality Assurance SeleniumEasy.Com
India India
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
-- There are no messages in this forum --