In the previous post I went a bit about the details as to why the older FirefoxDriver will no longer work with Firefox 48 and beyond.
In this one I’ll go deeper into the new Geckodriver usage.
Install Selenium
Python
#Mozilla recommends creating a new virtual #enviroment before installing Selenium virtualenv env_name source env_name/bin/activate
Then, just install Selenium using a pip command. Note that the minimum version of Selenium required is 2.46.1
pip install selenium
Ruby
To be able to install Selenium, you will need to get the Ruby Gem.
gem install selenium-webdriver
JavaScript(Node.js)
npm install selenium-webdriver
Java
Easiest way to install Selenium is by using Maven
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.0.0-beta2</version> </dependency>
C#
Here you have 2 options, one by using a nuGet package or by downloading the .dlls from the Selenium site and adding them as a reference to the project.
At the time of this post writing, the nuGet package only has 2.53.1 as latest version, while by downloading the .dlls you’ll get 3.0.0-beta2.
Set up the Marionette executable
Just like Chrome, Opera, Internet Explorer or Microsoft Edge, from now Firefox will also require an executable that will run alongside the browser.
It can be downloaded from the Geckodriver Github release page, and Mozilla recommends that even though the project has been renamed to ‘geckodriver’, many of the Selenium users look for the old name ‘wires’. Because of that, the executable may need to be renamed to ‘wires’ in order to have it picked up automatically.
Add Marionette executable to system path
The Selenium client bindings will try to locate the geckodriver (or wires) executable from the system path therefore you will need to add the directory containing it to the system path.
Add Marionette executable to Windows system path
To add the Marionette executable to Windows system path you need update the Path system variable and add the full directory to the executable.
To do this, right-click on the Start menu and select System. On the left-side panel click Advanced system settings and then Environment Variables button from System Properties window. Now the only step left to do is to edit Path system variable and add the full directory to your geckodriver (you may need to add a semi-colon before doing this, if not already present) and you’re good to go.
Add Marionette executable to Unix system path
On Unix systems, you can just append the geckodriver to your system’s search path using bash command:
export PATH=$PATH:/path/of/executable/downloaded
And now, for the fun part, to update the existing tests using Marionette.
Updating your existing Selenium tests to use the Marionette-based Geckodriver
To be able to use Marionette in your tests you will need to update your desired capabilities to use it.
Python
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities firefoxCap = DesiredCapabilities.FIREFOX #we need to explicitly specify to use Marionette firefoxCap["marionette"] = True #and the path to firefox firefoxCap["binary"] = "path/to/firefox" driver = webdriver.Firefox(capabilities = firefoxCap)
Ruby
#Selenium 3 uses Marionette by default when firefox is specified #To use it for Selenium 2, pass it by using marionette: true Selenium::WebDriver::Firefox::Binary.path = "path/to/firefox" driver = Selenium::WebDriver.for :firefox, marionette: true
JavaScript(Node.js)
const webdriver = require('selenium-webdriver'); const Capabilities = require('selenium-webdriver/lib/capabilities').Capabilities; var firefoxCap = Capabilities.firefox(); //for now it's required to tell the Node.js binding //to use Marionette firefoxCap.set('marionette', true); var driver = new webdriver.Builder().withCapabilities(firefoxCap).build();
Java
DesiredCapabilities firefoxCap = DesiredCapabilities.firefox(); firefoxCap.setCapability("marionette", true); WebDriver driver = new FirefoxDriver(firefoxCap);
C#
var driver = new FirefoxDriver(new FirefoxOptions());
Using RemoteWebDriver in your Selenium tests
If you want to use RemoteWebDriver in any language, the following will allow you to use Marionette in Selenium Grid.
Python
firefoxCap = DesiredCapabilities.FIREFOX #we need to explicitly specify to use Marionette firefoxCap["marionette"] = True driver = webdriver.Firefox(capabilities = firefoxCap)
Ruby
#Selenium 3 uses Marionette by default when firefox is specified #To use it for Selenium 2, pass it by using marionette: true firefoxCap = Selenium::WebDriver::Remote::Capabilities.firefox marionette: true, firefox_binary: "path/to/firefox" driver = Selenium::WebDriver.for :remote, desired_capabilities: firefoxCap
Java
DesiredCapabilities firefoxCap = DesiredCapabilities.firefox(); firefoxCap.setCapability("marionette", true); WebDriver driver = new RemoteWebDriver(firefoxCap);
C#
DesiredCapabilities firefoxCap = DesiredCapabilities.Firefox(); firefoxCap.SetCapability("marionette", true); var driver = new RemoteWebDriver(firefoxCap);
1 Pingback