INDIA +91 882 616 7094 | USA +1 949 299 0280 | GERMANY +49 176 3465 1507 info@navyuginfo.com

Meanwhile, A conversation is going on b/w two Automation Engineers somewhere in parallel universe:

Jai: Hey, Could you please check my scripts? Its running fine on Chrome and IE browsers but Firefox.
Veeru: Hmm, did you check the Selenium and Firefox version compatibility?
Jai: Not Really, It’s too hard to remember the version compatibility, Why don’t they provide a common solution for all Firefox versions? just like chrome and IE.

Thakur: Hey Guys, Did you check one of the features in Selenium 3.0 (stable release)? It will resolve all your Firefox related version compatibility issues:

“* Firefox is only fully supported at version 47.0.1 or earlier. Support
for later versions of firefox is provided by geckodriver, which is
based on the evolving W3C WebDriver spec, and uses the wire protocol
in that spec, which is liable to change without notice.”

For Detailed change log:

https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG – Java
https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES – Ruby

What is GeckoDriver and from where would we get that?

Hold on!!! Lets first see what is “Gecko” smile?

Gecko is a web browser engine used in many applications developed by Mozilla Foundation and the Mozilla Corporation, most noticeably the Firefox web browser, its mobile version other than iOS devices, their email client Thunderbird and many other open source software projects. You can get more information about Gecko here – https://en.wikipedia.org/wiki/Gecko_(software)1

GeckoDriver is a proxy for using W3C WebDriver-compatible clients to interact with Gecko-based browsers i.e. Mozilla Firefox in this case. This program provides the HTTP API described by the WebDriver protocol to communicate with Gecko browsers. It translates calls into the Marionette automation protocol by acting as a proxy between the local and remote ends.

Earlier, this is how Selenium used to work with Firefox:

public class FirefoxTest {

	@Test
	public void openFirefox() {
		WebDriver driver = new FirefoxDriver();
		driver.get("http://www.navyug.com");
	}
}

You just write the code to instantiate the WebDriver and open Firefox. If you just run this code, you would see that Firefox browser would get opened and Navyug.com would be displayed in the browser. This is how it worked with Selenium 2.53.1 and before.

Now, What would happen if you use the same method to instantiate the Firefox in Selenium 3.0:

You will get a run-time error:

“java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;”

Here comes the Geckodriver, which would support all latest versions of Firefox (I tried with v50.0.1, and it worked like a cheese):

Steps to Download GeckoDriver

Follow the steps given below to download it –

  1. Open this Github page – https://github.com/mozilla/geckodriver/releases
  2. Download the latest release (depending upon your OS). Till date, geckodriver-v0.11.1-win64.zip is the latest windows version. So click on the link to download it

After that, Use the below method to work with geckodriver:

public class FirefoxTest {
	
	@Test
	public void FirefoxTest1() {
		System.setProperty("webdriver.gecko.driver",Path of your GeckoDriver.exe file);
		FirefoxDriver driver = new FirefoxDriver();
		driver.get("http://www.navyug.com");
	}
}

In Case you don’t want to increase the line of codes in your program, you can directly set the geckodriver path in your System’s Environment variable and use the traditional way to instantiate the webdriver.

Note: In case you are thinking, what happened to MarionetteDriver? it has been deprecated but still works. FirefoxDriver now defaults to use GeckoDriver, the wires.exe is now renamed to geckodriver.exe and we can still use legacy version of Firefox before version 48 by setting the marionette capability to false.

Well, you just have to:

set the Firefox driver capability “marionette” to false
set the firefox_binary capability to the path of your legacy firefox

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false);
capabilities.setCapability("firefox_binary",
       new File(path of your legacy firefox exe).
              getAbsolutePath());
WebDriver driver = new FirefoxDriver(capabilities);

I would write more on Browser Capabilities and Profiles in later articles. Thanks for your Time. Happy Learning!!

Jai: Woo Hooo!!!, My script is now working fine with all latest Firefox versions. smile

By – Vishal Singh, Software QA Lead