Introduction To Selenium Grid
What's Selenium Grid?
Selenium Grid is part of the Selenium Course
that specializes on running several tests across different browsers, operating systems, and machines in parallel.
Selenium Grid has 2 variations - the older Grid 1 and the Grid that is newer 2. Because Grid 1 is gradually being deprecated by the Selenium Group we will solely concentrate on Grid 2.
Selenium Grid uses a hub-node concept where you only run the test on just one machine called a hub, but the execution will likely be performed by different machines called nodes.
When to Use Selenium Grid?
Selenium Grid when you want to do just one both or one of following should be used by you:
- Run your tests against machines, operating systems, and different browsers all at the same time. This will ensure that the program you are examining is completely compatible using a wide range of browser-O.S mixes.
- Conserve time in the execution of your test suites. If you set up Selenium Grid to to operate, say, 4 evaluations at a time, then you'd not be unable to complete the whole package around 4 times quicker.
Grid 1.0 Vs Grid 2.0:
Following are the main differences between Selenium Grid 2 and 1.
Selenium Grid 1 has its own unique remote control that is distinctive from the Selenium RC server. They're two software.
Selenium Grid 2 is now bundled together with the Selenium Server jar file.
You must install and configure Apache Ant first before it is possible to use Grid 1.
You don't have to install Apache Ant in Grid 2.
Can only support Selenium RC commands/scripts.
Can help both Selenium RC and WebDriver scripts.
You can only automate one browser per remote control.
One remote-control can automate up to 5 browsers.
What is a Hub and Node?
- The hub is the central point where you load your tests into.
- There should simply be one hub in a grid.
- The hub is found only on an individual machine, say, a pc whose O.S is Windows 7 and whose browser is IE.
- Where the tests will be run the machine comprising the hub is, but you will start to see the browser being automated on the node.
- Nodes are the Selenium instances that may execute the tests that you loaded on the hub.
- There can be one or more nodes in a grid.
- Nodes can be launched on multiple machines with different platforms and browsers.
- The machines running the nodes need not be the same system as that of the hub.
The best way to Use and Install Grid 2.0?
In this part, you will use 2 machines. The very first machine is going to be while another machine will run a node, the system that will run the hub. For simplicity, let's call the device where the hub runs as "Device A" while the device where the node runs will be "Machine B". It is also significant to note their IP addresses.
Download the Selenium Server.
It is possible to put the Selenium Server .jar file anywhere in your hard-drive. However, for the reason of the tutorial, place it on the C drive of both Machine A and Device B. You are now done installing Selenium Grid after doing this. These measures will launch the hub and also the node.
- We are now going to establish a hub. Visit Machine A. Utilizing the command prompt, browse to the root of Device A's - C drive, because that's the directory where we put the Selenium Server.
- On the command prompt, type java -jar selenium-server-standalone-2.30.0.jar -function hub
- The hub should successfully be launched. Your command prompt should look like the picture beneath
Another way to check whether the hub is working is by making use of a browser. The port 4444 of Device A is, by default, used by selenium Grid for its web interface.
Also, it is possible to check if Device B can get the hub's web interface by starting a browser there and heading to where "iporhostnameofmachineA" ought to function as the IP address or the hostname of the device where the hub is working.
- Now that the hub is set up, we are likely to launch a node. Visit Machine B and launch a command prompt there.
- Browse to the root of Drive C and type the code below. We employed the IP address 192.168.1.3 because that is where the hub is running. We additionally used port 5566 although you may select any free port-number you desire.
- Your command prompt needs to be similar to the picture beneath, when you press Enter.
Go to the Selenium Grid internet interface and refresh the page. You ought to see something such as this.
At this point, you've already configured a simple grid. You're now ready to to perform a test remotely on Machine B.
Designing Test Scripts That May Run on the Grid:
To design test scripts that will run on the grid, we need to make use of the RemoteWebDriver items as well as DesiredCapabilites.
DesiredCapabilites are used to establish the type of OS and browser that we are going to automate
RemoteWebDriver can be used to set which node (or device) that our evaluation will run against.
To make use of the DesiredCapabilites object, you have to first import this program
To utilize the RemoteWebDriver object, you need to import these programs.
Using the DesiredCapabilites Item:
- Head to the web interface of the Grid and hover on an image of the browser which you want to automate. Take notice of the system along with the browserName revealed by the tool tip.
- In this instance, the platform is "XP" along with the browserName is "firefox".
- We shall make use of the platform along with the browserName in our WebDriver as shown below (of course you must import the necessary packages first).
Using the RemoteWebDriver Object:
Running a Sample Test-Case on the Grid:
- Import the necessary packages for RemoteWebDriver and then pass the DesiredCapabilities object that we created above as a parameter for the RemoteWebDriver item.
- Below is a straightforward WebDriver TestNG code that you can create in Eclipse on Device A. Once you run it, automation will be done on Device B.
- The test should pass.
- Selenium Grid is used to run multiple tests simultaneously in different browsers and platforms.
- Grid uses the hub- concept.
- The hub is the central point you load your tests.
- Nodes are the Selenium examples that will execute the evaluations that you loaded on the hub.
- To install Selenium Grid, you just need to obtain the Selenium Server jar file - the same file in running Selenium RC evaluations, utilized.
- There are 2 ways to check if the hub is running: one was through the command prompt, and also the other was through a browser
- To to perform test scripts you ought to use the RemoteWebDriver things and the DesiredCapabilities.
- DesiredCapabilites is used to set the kind of OS and browser that we will automate.
- RemoteWebDriver can be used to establish which node (or machine) that our test will run against.