Why Selenium Grid?

Selenium WebDriver can only execute your test cases on a single machine.

There are several problems with this setup:

  1. What if you want to execute your test cases from different Operating Systems?
  2. How to run your test cases in the different version of the same browser?
  3. How to run your test cases in multiple browsers?
  4. How to run your test cases in parallel?

All these problems are addressed in Selenium GRID.

Selenium Grid architecture is based on master-slave architecture. Master machine distributes test cases to different slave machines. There are 2 versions of Selenium Grid available. Selenium Grid 2.0 is the latest from Selenium. Selenium 1.0 was the earlier version. Most of the Selenium experts prefer using Selenium Grid 2.0 as it is packed with new features. Selenium Grid 2.0 supports both Selenium RC and Selenium WebDriver scripts.

Benefits Of Selenium Grid

  1. Selenium Grid gives the flexibility to distribute your test cases for execution.
  2. Can perform multi-browser testing.
  3. Can perform multi-OS testing.

Basic Terminology Of Selenium Grid:

Hub: Hub is the central to the Selenium Grid Architecture which receives all requests. There is only one hub in the Selenium Grid. Hub distributes the test cases across each node.

Node: There can be multiple nodes in Grid. Tests will run in nodes. Each node communicates with the Hub and performs test assigned to it.

Install Selenium GRID

Download Selenium Server jar file from Selenium’s official website. Open the command prompt and navigate to a folder where the server is located. Run the server by using below command

Copy to Clipboard

The hub will use the port 4444 by default. This port can be changed by passing the different port number in command prompt provided the port is open and has not been assigned a task. Status can be checked by using the web interface: http://localhost:4444/grid/console

Go to the other machine where you intend to setup Nodes. Open the command prompt and run the below line.

Copy to Clipboard

By repeating above node CMD among different machines, you will get:

MaxInstance is used to limit the number of browser initialization in a node.

For example, if you want to work with 2 Firefox and 2 IE then you can start the node using maxInstance.

Copy to Clipboard

MaxSession is used to configure how many numbers of browsers can be used parallel in the remote system.

Copy to Clipboard

Sample Grid Code

Here is the sample GRID test case using TestNG. To login to Gmail and enter username and password using Grid node machine/browser.

Copy to Clipboard

Conclusion

It is advisable to use Selenium Grid when you have to perform multi-browser testing and you have a large number of test cases.

Please let us know your queries related to Selenium Grid.