In this post:

  • Snippets
    • Groovy Pre gecko
    • Groovy After gecko
    • Java Pre gecko
    • Java After gecko
  • Portable Firefox 46 with Marionette Driver
  • Download GeckoDriver
  • Checks
    • Platforms Supported by Selenium
    • Browser compatibility
    • Check Firefox version ( 32-bit or 64-bit)
    • Check is Firefox portable
    • Selenium Errors
  • Recommended or tested Firefox and Selenium combinations
    • Table with Selenium Compability

You can be interested also in : Ubuntu server install google chrome in headless

This article provides step by step detailed guide how to use Firefox with Selenium GeckoDriver. This article uses the working combination of versions of Selenium, Firefox & GeckoDriver and shows how can be launched Firefox by providing up to date code snippets. The versions that we will be using in this article are –

  • Selenium – version 3.5.3
  • Firefox – version 52.3
  • GeckoDriver – version 0.18.0
  • 32-bit versions (64-bit versions and latest GeckoDriver and Selenium were crashing frequently)

Snippets

Groovy Pre gecko

  • Firefox test with Geb pre Gecko version
@Grab("org.gebish:geb-core:0.13.1")
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.53.0")
@Grab("org.seleniumhq.selenium:selenium-support:2.53.0")
@GrabExclude('org.codehaus.groovy:groovy-all')    //prevent error of the geb

import geb.Browser
Browser.drive{
          // driver.webClient.javaScriptEnabled = true
          go "https://www.google.com"
          println $("a").findAll {it1->
                          println    it1.text()
          }
}
  • Chrome test with Geb pre Gecko version
@Grapes([
    @Grab("org.codehaus.geb:geb-core:0.13.1"),
    @Grab("org.seleniumhq.selenium:selenium-chrome-driver:2.53.0"),
    @Grab("org.seleniumhq.selenium:selenium-support:2.53.0")
])
import geb.Browser
import org.openqa.selenium.chrome.ChromeDriver

b = new Browser(driver: new ChromeDriver())

b.drive {
    go "http://www.google.com"
    
    $("input", name: "q" ) << "blog.softhints.com"
}

Groovy After gecko

  • Firefox test with Geb pre Gecko version
@Grab("org.gebish:geb-core:2.0")
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:3.5.3")
@Grab("org.seleniumhq.selenium:selenium-support:3.5.3")

import geb.Browser
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import java.util.logging.Level


System.setProperty("webdriver.gecko.driver","C:\\Users\\user\\geckodriver-v0.18.0-win64\\geckodriver.exe");

String baseUrl = "https://www.google.com"

FirefoxOptions options = new FirefoxOptions().setLogLevel(Level.OFF);

def browser = new Browser()
browser.driver =   new FirefoxDriver(options);

browser.drive{
	go  baseUrl
	println $("a").findAll {it1->
		println    it1.text()
	}
}

Java Pre gecko

  • Firefox test with java pre Gecko version
public class FirefoxNoGeckoTest {
	public static void main(String[] args) {
		WebDriver driver = new FirefoxDriver();
		driver.get("http://www.google.com");
	}
}

Java After gecko

  • Firefox test with java pre Gecko version
public class FirefoxGeckoTest {
	public static void main(String[] args) {		System.setProperty("webdriver.gecko.driver","C:\\PathToGecko\\geckodriver.exe");
		WebDriver driver = new FirefoxDriver();
		driver.get("http://www.google.com");
	}
}

Portable Firefox 46 with Marionette Driver

  • Portable Firefox test
System.setProperty("webdriver.gecko.driver", "C:\\PathToGecko\\geckodriver.exe");

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

FirefoxBinary binary = new FirefoxBinary(new File(firefoxPortablePath));

WebDriver driver = new FirefoxDriver(binary, createFirefoxProfile(), capabilities);
  • Firefox testing code in case of problem
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
System.out.println("Setup gecko driver");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
System.out.println("Prepare capabilities");
capabilities.setCapability("marionette", true);
System.out.println("Start new driver");
WebDriver driver = new FirefoxDriver(capabilities);
System.out.println("Open test page");
driver.get("http://www.google.com");
System.out.println("Close");
driver.quit();

Download GeckoDriver

Use the steps given below to download GeckoDriver –

  1. Open this page – Gecko Releases

  2. Download the appropriate release (preferred to be a recent one) based on whether your Firefox is 32-bit or 64-bit and the OS version.

  3. Unzip the file – geckodriver.exe and place it on accessible folder

P.S. If you choose bad place you can get error. For more information check Error 3 below.

More info for Gecko driver

Checks

Platforms Supported by Selenium

Due to the high number of version and platforms you need to be sure that what you are using is compatible with Selenium. And be careful because the things are changing very fast in the world of automation testing.

Platforms Supported by Selenium

Check latest Selenium version

  1. Open browser

  2. Visit:

2.1 You needed for Firefox and Chrome
Selenium Java

2.2 Firefox only
Selenium Firefox Driver

2.3 Chrome only
Selenium Chrome Driver

Browser compatibility

You need to check the browser compatibility before opting to test with Selenium:

SeleniumHQ browser compability

This might help to save your precious time. You have to search for something like:

3.4.0

  • Geckodriver 0.16 is strongly recommended
  • LiFT package is now available as a separate maven dependency.
  • Deprecated numerous constructors on RemoteWebDriver that are no longer useful.

Check if Firefox version ( 32-bit or 64-bit)

There are several versions of GeckoDriver depending on OS and 32-bit or 64-bit version. Based on your requirements you can download the corresponding GeckoDriver. Next you can check whether your Firefox is 32-bit or 64-bit.

  1. Open Firefox browser and click on the menu (hamburger icon from the right corner)

  2. Click on Help icon (question mark)

  3. Click on About Firefox. About Mozilla Firefox popup would be displayed

  4. Check if Mozilla Firefox is 32-bit or 64-bit

More info : Find what version of Firefox you are using

Check if Firefox is portable

  1. Windows Start menu

  2. Control Panel

  3. Programs and features

  4. Search Firefox in the program list

Known Selenium Errors

Error 1. Webdriver Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms

Usually the reason for this error is that the version of Selenium Server is not compatible with Firefox and does not know how to work with the newer version of Firefox.

Solutions

  • Update to newer version of the Selenium Server that supports the newer version of Firefox.
  • check browser compability( the section - checks / Browser compatibility )
  • Downgrade Firefox ( sometimes this is the best option with the least efforts). Here is the list of older versions of firefox: Firefox versions
  • Explicitly block the automated update for Firefox (this will prevent future problems of this kind)

Error 2. Exception in thread “main” Java.lang.IllegalStateException

If you use old version of Firefox 46 and latest version of Selenium (Selenium 3.7.1) then you may face the above mentioned error.

Solution

  • downgrade selenium driver
  • update Firefox version

Error 3. Connect to localhost:28379 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused

Reasons could be:

  • blocked access or unreacheable of the geckodriver.exe.
  • old stuff in Mozilla cache
  • hanging process with old configuration

Solution

  • verify gecko driver location
  • use accessible location for gecko driver ( avoid temp, network drives etc)
  • clean browser cache
  • restart machine in order to clean old processes

Recommended or tested Firefox and Selenium combinations

Pre Gecko Firefox Selenium combinations

  • Option 1

  • Selenium 2.39

  • Firefox 27

  • Option 2

  • Selenium 2.43

  • Firefox 35

  • Option 3

  • Selenium 2.53

  • Firefox 46

Gecko Firefox Selenium combinations

  • Selenium – version 3.5.3
  • Firefox – version 52.3
  • GeckoDriver – version 0.18.0

Table with Selenium Compability

Selenium Firefox GeckoDriver Chrome ChromeDriver
2.43 35.0 - 40 -
2.53.1 46.0 - 50 -
3.0.0-beta2 48.0 0.10.0 51-53 2.23
3.0.0-beta4 49 11 54 2.24
3.0.1 49 0.11 55-56 2.27
3.3.1 52.0 15 57 2.29
3.4.0 54.0 0.18.0 59 2.30
3.6.0 56.0 0.19.0 61 2.30