Oh, Marionette, My Dear

When I was running a UI test locally I encountered this in the log file:

[exec] INFO: Retrying request to {}->http://localhost:14804
[exec] Jul 30, 2018 10:17:34 AM org.apache.http.impl.execchain.RetryExec execute
[exec] INFO: I/O exception (java.net.BindException) caught when processing request to {}->http://localhost:14804: Address already in use: connect

Sometimes even the was hung and the browser was closed after a while. So basically I couldn’t execute a single UI test locally that frustrated me.

I will say a few words about the environment I work with. “There is no use saving it until later.” (To use the words of  Richard Brautigan’s words, which is a favorite sentence of mine from ‘In Watermelon Sugar’.)

The test framework I work with is based on top of Selenium Webdriver, it is an extra layer – please don’t ask why. The implementation of this framework is done by another team. Details are overspread, so a lot of digging required if I want something to know.

Spoiler alert!
This framework is launching Firefox 52 by default.

Let’s go back to the issue.

I asked Google about this message and found:

seem to be exhausting your ports

Yes, seems legit. But I still didn’t understand why and what was happening.

Then I found an issue reported to SeleniumHQ on their Github describing the problem. The following comment could be read there:

Selenium uses Apache HttpClient wich support persistent connections. But for firefox, httpd.js (the Firefox Httpd server for unit tests) doesn’t support it…
An issue (and some fixes) open for a long time now.

This Firefox issue was opened 10 years ago, and its status is NEW as of 2018!

The closing comment of the issue on Github was:

This issue will definitely remain not fixed in FirefoxDriver. Let’s hope Marionette will utilise sockets more carefully.

Oh, wait! Marionette?

This was the hint to check the framework implementation, to check that how it launches the browser. And yes, I eventually found that Marionette was explicitly set to false.

 

What have I learned about Marionette from this investigation?

What is Marionette?

If you want to perform UI tests with browser chrome or content, Marionette is the tool you’re looking for! You can use it to control either web content, or Firefox itself.

A test engineer would typically import the Marionette client package into their test framework, import the classes and use the class functions and methods to control the browser. After controlling the browser, Marionette can be used to return information about the state of the browser which can then be used to validate that the action was performed correctly.

Quoted from Firefox Docs.

The fact is that starting with Firefox 47, Firefox is using a new automation driver for Gecko engine called Marionette.

Why Was This Change?

The driver used to automate Firefox was an extension included with each client. But this extension was dropped, probably due to the change of policy which now requires all the extensions to be signed by Mozilla.

Firefox – Geckodriver – Marionette – Selenium

Marionette is the new driver that is coming with Firefox. This driver has its own protocol which is not directly compatible with the Selenium/WebDriver protocol. This is where Gecko comes into the picture. Gecko driver (previously named wires) is an application server implementing the Selenium/WebDriver protocol. It translates the Selenium commands and forwards them to the Marionette driver.

How to Launch Firefox With Marionette?

Now Selenium WebDriver needs to support this new driver to interact with Firefox, which means that testers have to initialize the test script to use Firefox using GeckoDriver explicitly.

You need to follow the steps:

  1. Download the latest available version of Marionette Driver (aka geckodriver). Visit the browser driver download page.
  2. Unzip the file (if zipped) and place the file in a known folder on your system.
    If your OS is Unix Based it must be executable
    chmod +x <driver_name>
  3. Optional: Add this known folder to your system path

How to Launch Firefox With A Custom Profile and with Marionette?

MarionetteDriver class did exist.

In the source code of the MarionetteDriver.java (selenium-firefox-driver version 3.0.1) there is a @deprecated text. It says: “One should use FirefoxDriver with capability marionette = true or false respectively.

In selenium-firefox-driver version 3.13.0 API MarionetteDriver class is already out of the picture.

Thus. First you have to instantiate a capability object and then add the profile object to the capability along with setting marionette capability to true. Once you have done that you can now instantiate your FirefoxDriver with the capability object as constructor argument.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s