Home Guide GeckoDriver vs Marionette: Differences

GeckoDriver vs Marionette: Differences

Shreya Bose, Technical Content Writer at BrowserStack -

The best way to approach this topic is to gain a clear understanding of both Marionette and GeckoDriver.

What is GeckoDriver?

Gecko is a browser engine developed by Mozilla Foundation and the Mozilla Corporation. It is used to power the Firefox browser, the Thunderbird email client and other applications.

Gecko supports open Internet standards and applications use it to display web pages or even the user interface itself (by rendering XUL). Its rich programming API makes it a perfect choice for powering Internet-enabled software such as browsers, online content and client/server.

GeckoDriver serves as a proxy between WebDriver enabled clients and the Firefox browser. In other words, GeckoDriver is a link between Selenium tests and the Firefox browser. It is a proxy for using W3C WebDriver-compatible clients that lets them interact with Gecko-based browsers.

Before Selenium 3, Firefox was the default browser for the automation framework. But since Selenium 3 does not have any native implementation of Firefox, all driver commands have to be directed through GeckoDriver. GeckoDriver has to exist as an executable file in one of the system paths before starting Selenium tests. Firefox implements WebDriver protocol using the executable file GeckoDriver.exe. This starts a server on the system and all tests communicate with this server to run the tests.

Using GeckoDriver instead of the default Firefox driver provides a major advantage in terms of compatibility. GeckoDriver uses W3C (the universally defined standard) WebDriver protocol to communicate with Selenium. Because of this, Selenium users do not have to create a new version of WebDriver to test every browser version. They can use the same WebDriver for multiple versions of Firefox.

Downloading and Installing GeckoDriver

Download GeckoDriver as an executable file by following the steps below:

  1. Visit https://github.com/mozilla/geckodriver/releases
  2. Select the right version of GeckoDriver for the operating system being used
  3. Once the ZIP file is downloaded, extract its contents into a folder on the system
  4. Take note of the location in which the file has been extracted. This will be needed later to instantiate the driver.

How to Initialize GeckoDriver?

This can be done in two ways:

1. Using DesiredCapabilities

Set the system property for Gecko Driver.

Syntax

System.setProperty("webdriver.gecko.driver","Path to geckdriver.exe file");

Example

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

Now, set Desired Capabilities. They help Selenium understand the browser name, version and operating system in order to execute automated tests.

Code to set GeckoDriver using DesiredCapabilities

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);

Complete code

System.setProperty("webdriver.gecko.driver", driverPath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);
driver= new FirefoxDriver(capabilities);

2. Using Marionette Property

Before using this method, scroll down to read about Marionette and its role in the testing landscape.

Use the code below to initialize GeckoDriver using Marionette property:

System.setProperty("webdriver.gecko.driver","D:\\Downloads\\GeckoDriver.exe");
Using this method eliminates the need for using DesiredCapabilities.

Try using the code below to launch Firefox using GeckoDriver

package com.browserstack.demo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class GeckoDriverDemo {

String driverPath = "D:\\BrowserStack\\GeckoDriver.exe";
public WebDriver driver;

@Before
public void startBrowser() {
System.setProperty("webdriver.gecko.driver", driverPath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);

}

@Test
public void navigateToUrl() {
driver.get("https://www.browserstack.com");
}

@After
public void endTest() {
driver.quit();
}

}

If one is interested to try running an automated test on a real device cloud,

Try Automated Testing for Free

What is Marionette?

Marionette is an automation driver that works with the Gecko engine. It is designed to remotely control the UI or the internal JavaScript of a Gecko-based platform like Firefox. It can control menus, functions, and content, allowing developers to automate multiple user actions. Additionally, Marionette can also read the properties and attributes of the DOM.

Marionette is similar to Selenium as it uses a lot of the same structure and API as the latter. However, it does include certain commands to interact with Gecko’s chrome interface. The point of using Marionette is to act as Selenium does for web content – enabling the tester to remotely control a user agent.

Marionette has two parts:

  1. A server to receive requests and execute in Gecko
  2. A client that sends the commands

It is best to use Marionette to run UI tests on Firefox. Typically, a tester would import the Marionette client package into their automation test framework, import the classes, and use class functions and methods to replicate user actions on the browser. Marionette can also return information about the browser’s state which can help validate that the automated action was executed accurately.

How to setup Marionette?

Download the Mozilla executable for Marionette from https://github.com/mozilla/geckodriver/releases

After this, Selenium client bindings will attempt to locate the GeckoDriver executable. Add the directory with the executable to the system property with the following code:

System.setProperty("webdriver.gecko.driver", "Path to geckodriver.exe file");

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("marionette", true);

driver = new MarionetteDriver(capabilities);

driver.get("https://google.com");

System.setProperty("webdriver.gecko.driver", "Path to geckodriver.exe file");

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("marionette", true);

driver = new MarionetteDriver(capabilities);

driver.get("https://google.com");

Differences between GeckoDriver and Marionette

What’s important to understand is that these two are not competing elements, but rather form part of the same architecture needed to run automated tests on Firefox browser.

  • When running automated tests on Firefox, the browser implements WebDriver protocol using GeckoDriver.exe. This starts a server to which all tests are communicated. The server translates calls into the Marionette automation protocol. Essentially, Marionette is a proxy between local and remote ends.
  • Marionette combines a Gecko component (the Marionette server) with an external component (the Marionette client) in order to run tests. The server ships with Firefox. Download a Marionette client or use the in-tree client to be able to use this server.

If a tester intends to run Selenium tests on Firefox, it is important to have clarity on these drivers. Know how they work, so that you can make them work for you.

BrowserStack Logo Run Selenium Tests on 2000+ Browsers & Devices Get Started Free