Understanding the Selenium Grid 4

30 / Sep / 2022 by Sriyansh Jain 0 comments

Selenium Grid is an open-source tool to automate web browsers. It allows us to achieve parallel execution of tests on different machines with the benefit of executing the same test suite on all the machines simultaneously. The aim is to make testing more efficient and decrease the test execution time. It also aids in lessening network traffic by distributing requests amongst all servers.

Selenium Grid can be primarily used for cross-browser testing, cross-platform testing, and cross-browser compatibility testing. It can be used for functional and non-functional testing. It can also be used for performance testing of any web application.

Components of SELENIUM GRID

1. Distributor

It is liable to register and keep track of all Nodes and their capabilities. It is used to query the New Session Queue and then process pending new session requests

2. Session Map

It is used to maintain a mapping between the session ID and the address of the Node on which the session is running.

3. Router

It acts as the entry point for the Grid. It is an integral part of the Grid which can be exposed to the wider Web. It can receive all external requests, and send them to the correct component, without overburdening any component which is not needed in the process.

4. Hub

The hub is the centrist point where tests are loaded into. There is only one hub in a grid. It can be launched in a single machine only. 

5. Nodes

Selenium instances are used to execute the tests loaded in the hub. There can be more than one node in a grid. Nodes can launch on several machines with multiple platforms and browsers.

6. Session Queue

The New Session Queue adheres to the FIFO ordering for all the new sessions which are requested. It consists of configurable parameters in order to set up the request retry interval. and request a timeout.

7. Event Bus

The Event Bus works as a communication path between the Distributor, Nodes, Session Map, and New Session Queue. The Grid performs most of its internal communication by avoiding expensive HTTP calls and messages.

Selenium Grid 3 vs Selenium Grid 4

Different Grid Types

Previously in Selenium Grid version 3, only Hub and Node(s) were used. Selenium 4 has some new updated and advanced features including two more types of Grid. Below mentioned are the three grid types supported in Selenium 4:

1. Standalone Mode 

In the Standalone mode, the Selenium server executes everything in-process. Standalone is a union of all the components of Selenium Grid. If we want to run Hub and Node on the same machine, we can use this mode. It is invoked by running the below-mentioned command on the terminal -> 

java -jar selenium-server-4.4.0.jar standalone

The Grid automatically analyzes the WebDrivers for Chrome and Firefox that are present on the system.

The server is listening on http://localhost:4444/ which is the same address used in the configuration of the Remote WebDriver. The Chrome WebDriver is only registered once the test code is executed.

2. Hub and Node Grid

This is the traditional technique to use the Grid for Selenium test automation that consists of two major components – Hub and Nodes

Hub is the amalgamation of the following components:

    • Router
    • Distributor
    • Event Bus
    • New Session Queue
    • Session Map

  •  Starting Hub in the machine using:
java -jar selenium-server-4.0.0.jar hub 
  • A node having the same machine

    java -jar selenium-server-4.4.0.jar node
  • A node having a different machine

    java -jar selenium-server-4.4.0.jar node --detect-drivers true --publish-events tcp://{hubIP}:4442 --subscribe-events tcp://{hubIP}:4443
  • hubIP – Displayed in the cmd logs on registering the hub

3. Fully Distributed 

It can perform in a fully distributed manner, with each piece executing its procedure. In this approach, we have to kickstart all the components individually like Router, Distributor, and more. It is used when we have a larger size Grid to be set up.

  •  Session Map
    • Maps the Session Ids for the executing node sessions
    • Kickstart the Session Map with the help of the below-mentioned command:

java -jar selenium-server-4.4.0.jar sessions
    • It maps the Session IDs to the node the session is presently running on 
  • Event Bus
    • It will be used to communicate between different components of the Grid
    • Start the Events Bus using the below-mentioned command:

      java -jar selenium-server-4.4.0.jar event-bus
  • Session Queue
    • Appends the new session requests to a queue
    • This queue will be refined by the distributor later
    • Start the Session Queue using the below-mentioned command:

      java -jar selenium-server-4.4.0.jar session queue
      
  • Distributor
    • Nodes inscribe to this Distributor
    • The distributor verifies the Session Queue and then assigns the new sessions to the inscribed node which is accessible to run the sessions
    • Start the Distributor using the below-mentioned command:

      java -jar selenium-server-4.4.0.jar distributor --sessions http://192.168.0.112:5556 --sessionqueue http://192.168.0.112:5559 --bind-bus false
      
  • Router
    • Navigates the requests to accurate components
    • The entry point of Grid
    • Start the Router using the below-mentioned command:

      java -jar selenium-server-4.4.0.jar router --sessions http://192.168.0.112:5556 --distributor http://192.168.0.112:5553 --sessionqueue http://192.168.0.112:5559
      
  • Node
    • Start node in the same machine:

      java -jar selenium-server-4.4.0.jar node
    • Start node in a different machine:

      java -jar selenium-server-4.4.0.jar node --detect-drivers true --publish-events tcp://192.168.0.112:4442 --subscribe-events tcp://192.168.0.112:4443


Advantages of Selenium Grid

  1. Open Browser: Selenium is an open source and easily accessible automation framework having no upfront costs. So, users can save lots of money here and utilize them for other good reasons.
  2. Support Multiple Browsers: Firefox, Chrome, IE, etc. 
  3. Support Multiple Architecture and OS: Windows, Linux, UNIX, Mac OS, etc.
  4. Escalates Test Execution Time: It boosts up the completion time of the test suite as it can execute multiple tests in parallel. For instance, if we have 5 nodes and we want to run a test suite of 60 tests then it will take 6 times less time than a single machine that runs the same test suite without Selenium Grid. When a node is idle, it picks up the test case waiting in the execution queue on its own.
  5. Execution of Cloud Based: Reliability, Availability, Software Maintenance Cost, and Save Hardware.
  6. Framework and Language Support: It holds up all crucial languages like Java, C#, Python, JavaScript, Perl, Ruby, and programming languages for software test automation.


Disadvantages of Selenium Grid

  1. Cost: Additional cost for the project as it needs extra machines as Nodes.
  2. Poor Scalability: It has comparatively poor scalability as compared to many present-day applications. It is inadequate to increase or decrease demand. 
  3. Reconfiguration: It is static. Each server is customized beforehand with a subset of the needed browser instances available. If you want to differ this, you have to reconfigure it.
  4. Need skilled engineers: Selenium Grid requires skilled engineers to create and maintain things and IT approval. 


Summary

At last, we can say that It will increase the marketing strategy for the big growing companies in the coming future. It is having wide scope in regards to growing Industry standards. It assists with the deployment of non-defective code. A Grid contains a single Hub and one or more Nodes. Both can be used with the help of a selenium-server.jar executable. The Hub receives a test that needs to be run along with detailed information on which browser(Firefox, chrome) and platform (i.e. Windows, Linux/Unix, etc) where the test should be executed. Since the Hub is aware of each registered Node and its configurations, it picks up any available Node which contains a  browser-platform combination that is already requested.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *