Gecko Marionette Firefox Driver with Selenium 3.0

Many of you know that Selenium 3.0 beta has been released and in this version of Selenium, you can open Firefox in a different way. You need to use Gecko driver a.k.a Marionette driver to launch Firefox. Before Selenium 3.0 we can launch Firefox by default without any property settings. On the other hand, we need ChromeDriverServer and IEDriverServer executables for chrome and Internet Explorer browsers. Now, with Selenium 3.0 we need to set Gecko (Marionette) driver executable to use Firefox and in this article I will show you how to accomplish this.

Marionette is the next generation of FirefoxDriver.

Step by Step Explanations to use Gecko a.k.a Marionette Driver

Method 1: Set Gecko a.k.a Marionette Driver path as webdriver.gecko.driver Property

Step-1: Go to https://github.com/mozilla/geckodriver/releases and download latest release of geckodriver.

marionette

Step-2: Create a new folder as “C:\Marionette” and extract the zip file inside this folder.

gecko

Step-3: Now, we should set webdriver.gecko.driver System property to the “C:\Marionette\geckodriver.exe” path.

Test Code:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>MarionetteFirstTest</groupId>
    <artifactId>MarionetteFirstTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.0-beta2</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * Created by ONUR BASKIRT on 01.09.2016.
 */
public class MarionetteFirstTest {
    //Declare a static driver variable
    static WebDriver driver;

    //Setup Driver
    @BeforeClass
    public static void setupTest() {
        //Set GeckoDriver (Marionette Driver) path as system property
        System.setProperty("webdriver.gecko.driver", "C:\\Marionette\\geckodriver.exe");
        //Now, you can create a new FirefoxDriver instance
        driver = new FirefoxDriver();
    }

    @Test
    public void checkTitleTest() {
        //Navigate the swtestacademy.com
        driver.navigate().to("http://www.swtestacademy.com");
        //Maximize the browser
        driver.manage().window().maximize();
        //Check the title
        assertThat(driver.getTitle(), is("Software Test Academy"));
    }

    //Close Driver is now working for webdriver 3.0 Beta2
    //Thats why I commented out this section.
    //Reference: https://github.com/SeleniumHQ/selenium/issues/2667
    /*@AfterClass
    public static void quitDriver() {
        driver.quit();
    }*/
}

Test Result:

marionette

Method 2: Set Gecko (Marionette) path as Environmental Variable

Step-1: Copy the geckodriver.exe’s folder path. In our case it is “C:\Marionette

Step-2: Use RapidEE or go to Windows System Properties -> Environmental Variables  and then click to Path and add this folder to Path variable.

gecko

Step-3: Restart the PC that your settings take effect!

After restart, you can directly create FirefoxDriver instance without set the System property every time. Your test code will look like this.

import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * Created by ONUR BASKIRT on 01.09.2016.
 */
public class MarionetteSecondTest {
    //Declare a static driver variable
    static WebDriver driver;

    //Setup Driver
    @BeforeClass
    public static void setupTest() {
        //Create FirefoxDriver instance without set the System property
        driver = new FirefoxDriver();
    }

    @Test
    public void checkTitleTest() {
        //Navigate the swtestacademy.com
        driver.navigate().to("http://www.swtestacademy.com");
        //Maximize the browser
        driver.manage().window().maximize();
        //Check the title
        assertThat(driver.getTitle(), is("Software Test Academy"));
    }

    //Close Driver is now working for webdriver 3.0 Beta2
    //Thats why I commented out this section.
    //Reference: https://github.com/SeleniumHQ/selenium/issues/2667
    /*@AfterClass
    public static void quitDriver() {
        driver.quit();
    }*/
}

 

4 thoughts on “Gecko Marionette Firefox Driver with Selenium 3.0”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.