Later edit:If you don’t want to go through the trouble of setting up your own Selenium Grid infrastructure, you could just use Endtest, since they provide codeless automated testing, a cross-browser cloud infrastructure and mobile device lab, video recordings of test runs, etc. And it’s mostly FREE.
Selenium Grid is a part of the Selenium Suite that specializes in running multiple tests across different browsers, operating systems, and machines in parallel.
Selenium Grid has 2 versions — the older Grid 1 and the newer Grid 2. We will only focus on Grid 2 because Grid 1 is gradually being deprecated by the Selenium Team.
Selenium Grid uses a hub-node concept where you only run the test on a single machine called a hub, but the execution will be done by different machines called nodes.
You should use Selenium Grid when you want to do either one or both of following:
Following are the main differences between Selenium Grid 1 and 2.Grid 1Grid 2
Selenium Grid 1 has its own remote control that is different from the Selenium RC server. They are two different programs.
Selenium Grid 2 is now bundled with the Selenium Server jar file
You need to install and configure Apache Ant first before you can use Grid 1.
You do not need to install Apache Ant in Grid 2.
Can only support Selenium RC commands/scripts.
Can support both Selenium RC and WebDriver scripts.
You can only automate one browser per remote control.
One remote control can automate up to 5 browsers.
In this section, you will use 2 machines. The first machine will be the system that will run the hub while the other machine will run a node. For simplicity, let us call the machine where the hub runs as “Machine A” while the machine where the node runs will be “Machine B.” It is also important to note their IP addresses. Let us say that Machine A has an IP address of 192.168.1.3 while Machine B has an IP of 192.168.1.4.
**Step 1**Download the Selenium Server by here.
**Step 2**You can place the Selenium Server .jar file anywhere in your HardDrive. But for the purpose of this tutorial, place it on the C drive of both Machine A and Machine B. After doing this, you are now done installing Selenium Grid. The following steps will launch the hub and the node.
Step 3
**Step 4**Another way to verify whether the hub is running is by using a browser. Selenium Grid, by default, uses Machine A’s port 4444 for its web interface. Simply open up a browser and go to http://localhost:4444/grid/console
Also, you can check if Machine B can access the hub’s web interface by launching a browser there and going to where “iporhostnameofmachineA” should be the IP address or the hostname of the machine where the hub is running. Since Machine A’s IP address is 192.168.1.3, then on the browser on Machine B you should type http://192.168.1.3:4444/grid/console
Step 5
Step 6
Go to the Selenium Grid web interface and refresh the page. You should see something like this.
At this point, you have already configured a simple grid. You are now ready to run a test remotely on Machine B.
To design test scripts that will run on the grid, we need to use DesiredCapabilites and the RemoteWebDriver objects.
To use the DesiredCapabilites object, you must first import this package
To use the RemoteWebDriver object, you must import these packages.
Go to the Grid’s web interface and hover on an image of the browser that you want to automate. Take note of the platform, and the browserName showed by the tooltip.
In this case, the platform is “XP” and the browserName is “Firefox.”
We will use the platform and the browserName in our WebDriver as shown below (of course you need to import the necessary packages first).
Import the necessary packages for RemoteWebDriver and then pass the DesiredCapabilities object that we created above as a parameter for the RemoteWebDriver object.
Below is a simple WebDriver TestNG code that you can create in Eclipse on Machine A. Once you run it, automation will be performed on Machine B.
The test should pass.