In this article we'll show you how to set up your own Selenium Grid to run tests on various versions of Firefox.
If you are new to setting up your own Selenium Grid, we recommend you first read our other blogpost: Setting up and Maintaining your own Selenium Grid.
1. Download the Firefox versions you want to run tests on
The first step is to download the different versions of Firefox you want to run WebDriver tests on. Mozilla makes this very easy: you can use their FTP website to download the versions you want: https://ftp.mozilla.org/pub/firefox/releases/.
Once downloaded, extract and install these versions on the machine that will run your Selenium Node.
The clean solution is to extract and install these to a separate folder, for example C:\firefox\45
on Windows or /Users/Shared/firefox/45
(where 45 is the version number).
2. Register the different Firefox versions on your Selenium Grid
You need to indicate to your Selenium Hub (which is the server connecting the nodes to a Selenium Grid) which versions of Firefox your node supports.
This way, when you later run a test asking for a specific version of Firefox, the Grid knows what machine in the Grid is provisioned with the version you're requesting.
Simply edit your node.json file
(which the Selenium node uses to advertise its available browser combinations via java -jar selenium.jar -role node -hub http://hubHost:4444/grid/register -nodeConfig node.json
)
node.json
contains:
{
"capabilities":
[
{
"browserName": "firefox",
"version": "45",
"platform": "WINDOWS",
"maxInstances": 1
},
{
"browserName": "firefox",
"version": "46",
"platform": "WINDOWS",
"maxInstances": 1
}
],
"configuration":
{
"nodeTimeout":120,
"port":5555,
"hubPort":4444,
"hubHost":"localhost",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":1,
}
}
With this example, we'll notify the hub (which is running on hubHost port 4444) that this node has both Firefox 45 and Firefox 46 available for testing.
3. Running a test on a specific Firefox version
Once you registered a node to the Selenium hub (grid) with different Firefox versions, you can create tests that target different Firefox versions:
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class JavaSample {
public static final String URL = "http://key:secret@hub.testingbot.com/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "Firefox");
caps.setCapability("version", "46");
caps.setCapability("platform", "WIN10");
caps.setCapability("name", "My First Test");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("http://www.google.com/ncr");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("TestingBot");
element.submit();
System.out.println(driver.getTitle());
driver.quit();
}
}
4. Take advantage of TestingBot's large grid
Setting up a grid with all kinds of browsers, browser versions and platform combinations takes up a lot of time! Maintaining the grid: installing updates, fixing issues, debug network problems, speeding up VMs takes even more time...
Take advantage of the TestingBot Selenium Grid which has all browsers and versions installed, on a wide range of platforms. We offer all browser versions, ranging from Firefox 3 to Firefox dev/beta, Chrome, Safari, IE, Edge and many more browser combinations.