Many of you must have encountered a geckodriver error as you start scripting for Mozilla Firefox using the latest Selenium 3.0.0 Beta release. WHAT! It used to work perfectly fine with Selenium 2.0. What has changed now? What is gecko and what’s the relation with Selenium scripting?
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
What has changed now?
If you are getting the above error, you must have downloaded Selenium 3.0.0 Beta and Firefox browser version > 48.0. Right? Yeah! It should be.
- Earlier Scenario: To use Firefox with Selenium, use the “old” legacy Selenium FirefoxDriver provided and maintained by the Selenium project. The legacy driver is implemented as a Firefox extension. This extension is installed in the profile used by the driver when WebDriver launches Firefox.
- Current Scenario: Starting Selenium 3.0.0 Beta and Firefox browser version > 48.0, you will no longer be able to use the legacy FirefoxDriver provided by the Selenium project. Why? Mozilla has introduced two new features in Firefox browser that has disabled the legacy FirefoxDriver. The most important being – all browser extensions must be signed by Mozilla before the browser will allow them to load. The Selenium WebDriver Firefox extension introduces several valid security concerns for the browser, and as such, will not be signed by Mozilla’s security team. This, in turn, renders the extension inoperable, and thus Selenium can no longer communicate with Firefox using this legacy FirefoxDriver.
Then how to automate Firefox > 48.0 with Selenium 3.0.0 Beta?
Just like the other BrowserDrivers available to Selenium from other browser vendors, from Firefox 48.0 onwards, Mozilla itself (instead of Selenium project) has developed a new Firefox driver called Marionette-based Geckodriver, i.e. the mechanism used to drive the browser is now part of Mozilla Firefox itself. This driver code is entirely open source, and the geckodriver executable provided by Mozilla acts as a translator to take the HTTP calls from existing Selenium WebDriver to use a Marionette communication protocol over TCP that the browser understands natively. From Firefox 48.0 onwards it is mandatory to use this new Marionette-based Geckodriver developed by Mozilla.
What is Gecko?
Gecko is a web browser engine used in many applications developed by Mozilla Foundation and the Mozilla Corporation – notably the Firefox web browser including its mobile version other than iOS devices. Gecko is free and open-source software subject to the terms of the Mozilla Public License version 2.
Gecko offers a rich programming API that makes it suitable for a wide variety of roles in Internet-enabled applications, such as web browsers, content presentation, and client/server. Gecko is written in C++ and is cross-platform, and runs on various operating systems. Its development is now overseen by the Mozilla Foundation.
What is Gecko driver?
A Proxy for using W3C WebDriver-compatible clients to interact with Gecko-based browsers. Geckodriver provides HTTP API described by the WebDriver protocol to communicate with Gecko browsers, such as Firefox (version after 47). It translates calls into the Marionette automation protocol by acting as a proxy between the local and remote ends.
Marionette, the next generation of FirefoxDriver
How does it work?
Marionette consists of two parts:
- A server which takes requests and executes them in Gecko
- The client sends commands to the server and the server executes the command inside the browser.
- Add executable to system path – The Selenium client bindings will try to locate the geckodriver executable from the system path. You will need to add the directory containing the executable to the system path. On Windows you need to update the Path system variable to add the full directory path to the executable. Marionette is activated by default for Selenium 3.0.0. Even if you are working with older versions of Firefox browser, Selenium 3 expects you to set path to the driver executable by the webdriver.gecko.driver.
- Updating your tests to use Marionette – To use Marionette in your tests you will need to update your desired capabilities to use it.
Caution: Marionette and geckodriver are not yet feature complete. This means it does not yet offer full conformance with the WebDriver standard or complete compatibility with Selenium. Marionette support is best in Firefox 48 and onwards, although the more recent the Firefox version, the more bug fixes and features. Firefox 47 is explicitly not supported.
- Other work-around is to pin down your automation to use earlier versions of both Firefox and Selenium until a release of using GeckoDriver/Marionette is stable enough for the tests.
Hope this article helped you understand the geckodriver error you are getting while automating the test cases using the latest Selenium and Firefox browser versions. To help fellow automation testers, feel free to add your analysis in the comments below…
Looking for a Job Change in QA/Testing technology? Get Regular Job notifications @ WhatsApp!