Home >>Selenium Tutorial >Selenium WebDriver Running test on Firefox Browser

Selenium WebDriver Running test on Firefox Browser

Selenium WebDriver- Running test on Firefox Browser- Gecko (Marionette) Driver

We'll learn how to run your Selenium Test Scripts on your Firefox browser in this section.

Lets us first understand the basics of Gecko Driver before continuing with this section.

What is Gecko Driver?

The word Gecko refers to the Gecko browser engine which was developed as part of the Mozilla framework by Mozilla Foundation.

Gecko Driver serves as a link between your Selenium tests and your Firefox browser. It acts as a proxy for communicating with the Gecko based browser (Mozilla Firefox) for W3C WebDriver-compatible clients (Eclipse, Netbeans, etc.).

Marionette (FirefoxDriver's next generation) is started to turn on normal from Selenium 3. Selenium sends requests to GeckoDriver using the W3C Webdriver interface, which converts them into a protocol called Marionette. And if you deal with older versions of Firefox browser, Selenium 3 requires the webdriver.gecko.driver to set route to the manager executable.

Let's call a test case in which we'll try to simplify the following Firefox browser scenarios.

  • Launch Firefox browser.
  • Open URL: www.phptpoint.com
  • Click on the Custom Search text box
  • Type the value "Java"
  • Click on the Search button.

Our second test case will be generated within the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class.

Offer the name of your Class as "Second" and press "Finish" button.

step 2. Open URL: https:/github.com/mozilla/geckodriver/releases in your browser and click on the correct version to update GeckoDriver based on your current operating system. The 64bit edition of GeckoDriver for Windows is downloaded here.

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.

1. Using Desired Capabilities

First, we have to set the system property for Gecko Driver.

System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  

Below is the code to set gecko driver using DesiredCapabilities class.

DesiredCapabilities capabilities = DesiredCapabilities.firefox();  

Here is the complete code:

System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  
DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
        WebDriver driver= new FirefoxDriver(capabilities);

2. Using marionette property:

Gecko Driver may also be initialized using the proprietary marionette.


For this method the Necessary Capabilities code is not needed.

3. Using Firefox Options:

Versions of Firefox 47 or later include the marionette driver as a legacy system. Thus, it can be named a marionette driver using Firefox Options as shown below.

FirefoxOptions options = new FirefoxOptions();  

Step 3. It is now time to write. For each block of code we've inserted comments to illustrate the steps clearly.

import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  
import org.openqa.selenium.remote.DesiredCapabilities;  
public class Second {  
    public static void main(String[] args) {  
          // System Property for Gecko Driver   
System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );  
          // Initialize Gecko Driver using Desired Capabilities Class  
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();  
    WebDriver driver= new FirefoxDriver(capabilities);  
         // Launch Website  
        // Click on the Custom Search text box and send value  
        // Click on the Search button  
driver.findElement(By.className("gsc-search-button gsc-search-buttonv2")).click();    

Step4. Right click on the Eclipse code and select Run As > Java Application.

Step5. The output of above test script would be displayed in Firefox browser.