A Complete Guide to Selenium Grid 4: Architecture and Configuration
In the testing community, generally, when we refer to “Selenium,” we are talking about the Selenium client API that helps write test cases. Sometimes, we may mean Selenium IDE, but with the advent of no-code solutions in cloud platforms, Selenium record-and-replay, which was a hit, has lost its charm. However, we forget that Selenium is not just API or record-and-replay. It is made up of four components, and one of the most important among them today is Selenium Grid.
The execution of test cases on a single machine is only helpful till a certain threshold point. Beyond this point, the capabilities of a single machine start to hinder execution time and the costs associated with it. Therefore, we connect and distribute the test script on multiple machines with the help of Selenium Grid and wrap testing faster. The concept of Grid was launched in 2004, and continuing in the same domain, Selenium has come up with its fourth instalment as Selenium 4 which is also said to be revolutionizing in its existing pool.
This post aims to cover all the details around Selenium 4 and how it differs from its past versions. Later, we will try to execute code on Selenium Grid 4 to go deeper into its working and its drawbacks today. But to understand all this, we need to apprise ourselves a bit more about Selenium Grid and its working.
Table Of Contents
- 1 A brief introduction to Selenium Grid
- 2 What is Selenium Grid 4?
- 3 Components of Selenium Grid 4 – Architecture
- 4 Prominent Features of Selenium Grid 4
- 5 What’s different in Selenium Grid 4? Comparison with Selenium Grid 3
- 6 How to install Selenium Grid 4?
- 7 Drawbacks of using Selenium Grid
- 8 Testsigma – An alternative to Selenium Grid
- 9 Summary
- 10 Frequently Asked Questions
A brief introduction to Selenium Grid
The term “Grid” is not uncommon no matter what field you have worked in or are currently working in. The common usage of “Grid” is in power infrastructure and Selenium picks up from the same concept. A power grid looks as follows:
In this setup, a lot of the houses are provided with electricity that is generated at a single location and coming from a single transmission line. We can take this reference and put it in a computer perspective to create a grid of our own as this:
Here, the homes that were at the end of the line are replaced by the computers and we term them “nodes.” The black computer seen in this image is the one that delivers the “transmission line” to all the nodes. This is called a “hub,” and the transmission line is obviously instructions that need to be executed on these nodes.
This setup now becomes a grid, and when Selenium is run on this grid, we term this as “Selenium Grid.”
The concept of Selenium Grid is simple. When one system is used to run Selenium tests, they are not as efficient as we require them to be, considering the high complexity and size of test cases. To speed things up, we need to connect various other systems that can help us execute these test cases quickly and simultaneously. By configuring these systems with a one-time setup, the hub can provide instructions on what to execute at which system and the nodes can follow that. This is also called the distribution of tests and is sometimes also referred to as “distributed testing.”
So, what could be the criteria for distributing tests quickly and correctly? For this, we initialize node systems with varying configurations, which are generally the operating system or the browser.
As seen in the above image, the nodes are installed with different operating systems. We can also expand this by adding more nodes with the same operating system but different browsers, etc. In the end, Selenium Grid aims to run the test cases (Selenium based) on multiple systems simultaneously and wrap things faster.
What is Selenium Grid 4?
Selenium Grid has been in use since 2004 and it has been a popular software among testers since. Taking into consideration how fragmented our device market has become, regular major improvements in Selenium Grid are also required.
The latest of the lot in this department is Selenium Grid4 which takes just the name from its predecessor but not the code and working method. Selenium Grid4 is a grid system to run parallel and distributed tests on hubs and nodes. In addition, it contains multiple other components that were never part of Selenium 3 and have improved the mechanics of communication to “reflect a modern age of computing.” All of this will be discussed in further sections.
Components of Selenium Grid 4 – Architecture
Selenium Grid 4 provides its users with software that can deal with high-paced computing environments with integrated cloud services and much more. This is made possible through the following set of components:
- Session Map
- New Session Queue
- Event Bus
When put into a flow diagram, these components work as follows:
The first entry point of all the requests is a router. A router (similar to a network router) takes the request from the client (also termed an external request) and forwards them to the appropriate component.
So, for instance, there is a request on an ongoing session, it can directly be connected to the node as the session was already established. This is done by querying the session map. However, if it is a new request, the router analyzes it and forwards it to the session queue instead.
Another major feature of the router is to provide requests by maintaining a balance between the grid so that no node is overburdened.
A session by the client is mapped to the node and this information is kept inside the session map. The main usage of a session map comes when the router needs to enquire about a node related to a certain session to forward the request. Session map can provide the node ID and the request can therefore be forwarded to the node directly.
A new session request needs to be mapped to a particular node so that as long as that session sends requests, it is directed to the correct node. For this process to work, we need two things:
- Attaching new requests to a node.
- Keeping session-node mapping updated in the session map.
Both of these responsibilities are performed by the distributor. In addition, a distributor must have knowledge of all the nodes so that it can connect new requests to them. Therefore, whenever a node is added, it sends a note registration event to let the distributor know about it. To confirm this connection, the distributor sends acknowledgement through HTTP. If this is successful, the node is confirmed to be added and is assigned a session in future requests.
New session queue
The work of the new session queue component is to keep track of all the new session requests that have arrived for processing in the Grid. The new request is added as Router sends it to the queue after figuring out that it is a new request. The requests are saved on a first come first serve order. The distributor then polls these requests if a node is free and assigns this request to the node.
However, in polling and assigning a request, the distributor has to verify that the request should not have timed out. Else, it gets rejected and is deleted from the queue.
The communication between all the components i.e. Distributor, Node, Session Map, and New Session Queue happens through the event bus. HTTP communication is avoided as it is expensive (involves multiple calls).
The execution of tests in a distributed network happens on a node. There are multiple nodes connected in a grid and generally have different configurations to perform specific tests on them. To be assigned a request, the node should be registered to the Distributor with its configurations so that a request that requires those configurations can be connected.
Selenium Grid works in a hub-node mode, and here, nodes are just for executing the commands it receives. It does not evaluate or make judgments of any kind.
All these components combine to make a perfect system for test execution using Selenium.
Prominent Features of Selenium Grid 4
When a tester opts for Selenium Grid, they take advantage of the following features:
- Open source – Selenium is open source, old, and has a powerful global community. It helps us whenever we are stuck, or require guidance or a path to follow.
- Free to use – Selenium is free to use for everyone, from individuals to organizations. It helps bring down the costs of the project.
- Multiple configuration support – Selenium supports multiple configurations that include all the major operating systems and browsers. The tester can execute their tests on these combinations, including OS and browsers’ previous versions distributed to various nodes.
- Language support – Selenium Grid 4 comes with a long list of language support that helps write distributed test cases in the language of your choice without investing time in learning a new one.
- Cloud-based execution – Selenium Grid 4 takes the execution of tests to the cloud to help save local resources and use a reliable and robust infrastructure.
- Parallelism – Selenium Grid 4 supports parallelism, so the testers can execute test cases in parallel at various nodes. This, however, requires support from TestNG.
- Integrations – Selenium Grid can integrate well with the most significant tools and third-party cloud-based tools to perform testing without installing a single browser or setting up nodes.
What’s different in Selenium Grid 4? Comparison with Selenium Grid 3
Any software, when upgraded with a newer version comes with rectified anomalies of its predecessor, especially the most popular ones. So naturally, it is expected that any newer version will come up with new features and perform better than the previous version. It is also the case with Selenium Grid 4, and this section is dedicated to differentiating it from Selenium Grid 3 as much as possible.
The most appreciated feature of Selenium Grid 4 is its army of components dedicated to doing their fixed separate tasks and expanding the power of the grid. This structure was shown in the image above. On the contrary, Selenium Grid 3 worked on just two components:
The flow diagram would be as follows:
So there are no distributors or session queues for Selenium Grid 3.
Selenium Grid 4 code is written fresh and has no association with Selenium Grid 3 code. This removes any complex dependencies that prevent covering the loopholes of the system.
While Selenium Grid 3 can be configured by just the Hub-Node method, Selenium Grid 4 provides four options for its configuration. They are:
This provides flexibility to the tester, which is always a good thing in the software industry.
Single Jar for everything
Selenium Grid 4 provides a single jar for everything that you may need to set up the Grid on your infrastructure. This includes the required dependencies; therefore, the setup time, maintenance, and complexity are reduced drastically.
Apart from these major differentiators, obviously, we get improved performance, more features, and a much stronger grid to work on.
How to install Selenium Grid 4?
Alright! Now we have all the required information to install and configure Selenium Grid 4. To install Selenium Grid 4, first, we need to download the software to our local system. This can be done from the official Selenium Grid 4 web page.
Once the file gets downloaded, install it on the system as you would do for any other software.
How to Configure Selenium Grid 4?
The configuration of Selenium Grid 4 can be done by running various commands that target a specific task in Selenium Grid. These commands with their task are listed below:
Setting grid with secure communication and node registration
Get configuration help
If the tester wishes to use a separate session storage than local storage
Get help to know all the Selenium Grid commands
To get help based on a specific component
For example, for standalone use
For node session queue
Setting max sessions as 3 on standalone mode
Setting a session request timeout on Hub and disabling tracing
Setting session map server URL and server queue server URL
To start the Hub
Start a node with custom capabilities
These commands are sufficient to install, configure, set up, and start Selenium Grid 4 on the local network.
Drawbacks of using Selenium Grid
Selenium is widely used for web application testing, where Selenium Grid performs cross-browser testing. By distributing tests on nodes that host different browsers and different operating systems, we can efficiently run cross-browser tests to verify the correctness of the website on various platforms. But this arrangement comes at a cost that should be considered before starting out with Selenium Grid.
The most concerning fact about using Selenium Grid is that we need to provide dedicated resources to the runs. Each node is a system that has an operating system and browser installed. Even if we run the tests in parallel and simultaneously, the costs of purchasing these resources are very high. This is a rather bigger concern for individuals and startups.
Dedicated resources require regular monitoring and maintenance. This becomes more complex as the number of systems keeps adding up in our Grid. Higher maintenance would mean more hires and dedicated time from engineers to the infrastructure. And this graph keeps increasing as our system starts to scale more. This can shoot the budget of the testing phase and, in turn, the overall project.
Since we are dealing with resources on-premise, scaling is another challenge with Selenium Grid. If we consider the combination of operating systems, their versions, browsers, resolutions and then multiply them with mobile devices and their browsers, scaling up to this level is impossible. Somewhere or the other, we compromise on scalability, which means we compromise on the quality of web applications.
Everything in Selenium is connected through IPs and URLs. This is how the components talk to each other. Since these things are done manually, the cost of reconfiguring them when such a requirement arises is very high.
Selenium Grid is vulnerable to security issues as it is maintained and developed on-premise. An organization can start a Selenium Grid without analyzing or maintaining a security protocol or dedicated security team. This can create a loophole in the system, making it a critical issue for shareholders.
With so many issues with the Grid, it does not seem a perfect option to use it for testing our web application. Can we look a bit beyond Selenium and explore any option that might help us in a better way? I think we can!
Testsigma – An alternative to Selenium Grid
Out of all the issues discussed above, the main issue of Selenium Grid is maintenance and infrastructure complexity. Even if we can manage to create many nodes with diversified specifications, just the thought of maintaining them can be tiresome.
An excellent alternative to this is a platform that can host systems with different browsers and OS, can run automation tests, and provide zero maintenance overheads to the tester. These features are matched perfectly with Testsigma.
Testsigma is a cloud-based test automation tool that believes testers should be good at testing regardless of their programming skills. For this, the platform eliminates the usage of programming languages and keeps the medium of communication between a tester and the system in plain English using NLPs.
As far as cross-browser testing is considered, Testsigma provides all the browsers, their versions, operating systems, and their versions on their infrastructure. The tester just needs to select the correct specification, and a real device is opened on which the tester can either interact manually or run an automated test.
Testsigma is open-source just like Selenium and does not involve any maintenance overheads. You don’t need to maintain the session queues, systems, networking, or anything at all. Just log in to your account (which is free to create) and start testing from anywhere in the world. Such freedom is not possible in the on-premise solutions of Selenium.
The platform also provides a recorder facility to record test cases (or perform actions and convert them to actions automatically) and run them later on any specification. For testers who wish to perform web application testing including cross-browser testing, Testsigma is much smoother, easier, and more cost-effective than Selenium. You can give it a try by creating a free account and letting us know your experience in the comment section.
Try the Enterprise Features for Free for 30 Days!
Selenium Grid is one of the offerings provided by Selenium to run distributed test cases by connecting multiple systems. These connected systems are called Nodes whose work is to execute test cases (instructions) provided to them. They do not contribute more than that. The centralized system that connects these nodes and sends the instructions is called a Hub, and it is the main brain of the Grid.
This post was dedicated to the latest version of Selenium Grid which is also called Grid 4. Selenium Grid 4 is a fresh code that does not inherit from its earlier versions and tries to eliminate loopholes and anomalies and also provides newer methods that are more efficient. This version of Selenium Grid comes in four modes (which was one in earlier versions) and enhanced components to create a robust infrastructure.
However, Selenium Grid is not perfect. Its heavy infrastructure and complex communication methods can increase time consumption and costs dedicated to the testing phase. This can create a ripple effect on the overall project which was discussed in this post. As a tester, along with Selenium, we can try a cloud-based automation tool Testsigma that can do a better job, without any on-premise setups or complicated communication methods.
With this, we conclude the understanding of Selenium Grid 4. I hope this post will help you in web application testing in upcoming projects. Thank you for giving this post your valuable time.
Frequently Asked Questions
What are the supported grid types in Selenium 4?
Selenium Grid 4 supports four types:
Is Selenium 4 faster?
While Selenium 4 does apply newer features and components to the system, it is not proven to be faster than its predecessor. The main selling point of Selenium Grid is not speed but the variety that comes with this version.