LambdaTest Community

Find answers, support, and inspiration from other users

LambdaTest Community

What is selenium grid and how it works?

Can anyone please provide me some valueable information on what is selenium grid and how it works.

Up Vote Down Vote 0 Votes
Posted 4 months ago


Selenium Grid is a testing tool (which is a part of the Selenium Suite) that is based on the ‘client-server’ architecture. In Selenium Grid terminology, Client machine is termed as ‘Hub’ and server(s) are termed as ‘Nodes’.

Selenium Grid setup allows you to execute cross browser testing through a variety of different machines across different browsers (as well as different versions of browsers) & different operating systems. Hence, it brings the require amount of ‘parallelism’ & ‘distribution’ to your test execution environment.

A Selenium Grid setup can have only one Hub and ‘n’ number of nodes. The primary job of the ‘hub machine’ is to distribute the test case supplied to the ‘node machine’ which matches the capabilities/requirements required for executing the test case for performing cross browser testing. We would discuss more Hub & Node (which are the core components for the setup of Selenium Grid infrastructure) in further sections.

There are two versions of Selenium Grid available, namely Selenium Grid 2.0 & Selenium Grid 1.0. Selenium Grid 2.0 is most popular amongst automation testers since it supports Selenium RC (Remote Control) and Selenium WebDriver scripts.

Why Selenium Grid Setup Is A Smart Call To Make?

There are a number of benefits of Selenium Grid setup. Here, we have a look at some of the top advantages of Selenium Grid setup as a part of your test execution strategy for performing cross browser testing.

  • Reduced Execution Time – Selenium Grid setup can be used to execute multiple test cases on different browsers (and browser versions) and operating systems. You can also run multiple instances of Selenium RC along with the test configuring combinations. As the tests are executed in ‘parallel’ (scattered across different machines), the overall time consumed for cross browser testing trims down significantly.
  • Scalable & Maintainable – As we know, Selenium Grid setup reduces the amount of time required for ‘parallel testing’ by a huge margin, the entire solution is highly scalable. If you want to perform testing on a ‘new node’ (which could be Operating System/Browser), all it needs are few minor tweaks in the code with respect to the addition of capabilities, and your solution for the new node is ready. Perform Multi-Combination Testing – Using the Hub & Node feature of Selenium Grid setup, you can perform multi-OS, multi-browser, and multi-device verification of your source code. By default, the execution after the setup of Selenium Grid is not parallel in nature. In order to take the advantage of parallelism, the selenium tests should be written in a manner that takes ‘parallel execution’ for cross browser testing into account.

Primary Components Of The Selenium Grid Setup & Brief Look At RemoteWebDriver Workflow

In case you want to use the Selenium WebDriver to execute tests on a separate machine, you have to use Remote WebDriver interface. Since the tests (in normal scenarios) have to be executed on a different machine, RemoteWebDriver is based on the traditional ‘Client-Server’ model. The RemoteWebDriver consists of two main parts – Hub (Server) and Node(Client). Let’s have a detailed look at the same in this section.

Hub/Server – The Hub is the central component of the ‘Selenium Grid architecture’. It loads the tests that have to be executed. There can only be one ‘Hub’ which acts as the ‘Master’ in the setup of Selenium Grid infrastructure. Once the Hub receives an input/test case that needs to be executed, it searches for a Node (client) which matches the desired capabilities and diverts the ‘test execution request’ to the matching node.

For example, if you have setup a Selenium Grid with (hub + two nodes) where the node configuration is as below:

  • Node 1 – Windows 10, Chrome 73.0
  • Node 2 – Windows 10, Firefox 64.0

If there is a test case that has the ‘Desired Capabilities requirement’ – (Windows 10 + Chrome), the hub first receives the request for this requirement. By looking at the requirement, it diverts the execution request to Node 1.

Node – Node is a machine on which the tests are executed. Node can have a different configuration than the hub. There is no limit on the number of nodes that can be connected to the hub. Since the test code execution will occur on the node(s); it is recommended that you choose machines with the best possible configuration so that you can get the best performance out of your Selenium Grid setup.

Simple Representation Of The Selenium Grid Setup

Up Vote Down Vote 0 Votes
Posted 3 months ago