End-to-end Testing
How-tos & Guides
6 min read

Setting up Selenium Grid for cross-browser testing

Selenium Grid is an open-source project that enables you to run Selenium tests across browsers on your own infrastructure. In this tutorial, we'll cover how to set up Selenium Grid to run a basic set of tests.

Joel Adewole
Published July 8, 2022

Despite the dominance of Google Chrome’s market share, there’s still more than a third of web usage worldwide that occurs on non-Chrome browsers. Given the complexity of supporting thirty years of web standards, it’s not surprising that the same web application can present divergent behavior across browsers. This makes the task of testing across browsers especially important for developers who want to ensure a consistent, working experience for all users.

Testing across browsers presents its own challenges. For instance, Google Chrome can work on operating systems with little or no exception, while Safari only works on Apple systems like macOS, iPadOS and iOS.

This article will discuss what cross-browser testing is, what Selenium Grid is, and how to set up a Selenium Grid for cross-browser testing. You’ll need a working knowledge of web development, testing, and CLI scripting to follow along with this article.

What is cross-browser testing

Testing is an essential part of the software development process. There are many different kinds of testing that can be performed, such as security testing, unit testing, compatibility testing, API testing, and accessibility testing. What we’ll be focusing on in this article is cross-browser testing.

Cross-browser testing assesses the compatibility of web applications and sites across different browsers. This can be accomplished manually, by executing the test scenarios across all desired browsers, but this is time-consuming and inefficient. Instead, cross-browser tests can be set up to run in a fully-automated way by utilizing tools that support creating automating tests and running them automatically across browsers. .

What is Selenium Grid

Selenium is an open source test automation tool that allows you to write test scripts in different programming languages to create automated functional tests. It supports several popular browsers, including Internet Explorer, Google Chrome, Firefox, and Safari, and operating systems such as Windows, Linux, and macOS.

Selenium is available in the following distributions as a testing framework:

Selenium Grid will be the emphasis of this article. Grid, unlike the other Selenium distributions, is best used for:

Selenium Grid consists of two key sub-components:

Setting up Selenium Grid for cross-browser testing

To use Selenium Grid for cross-browser testing, we’ll need to set up a development environment that includes a hub and node.

Download and install the Selenium Server

Because the Selenium server is a jar file, make sure Java is installed and configured in the system PATH.

You can download the current version of the Selenium Server from the official website. There have been multiple version releases, so be sure to take note of the version you are using when following this guide.

Starting Selenium Server

After you’ve downloaded the standalone file, start a terminal in the jar file’s directory and type the following command:

java -jar selenium-server-4.2.0.jar -role hub

NOTE: Replace 4.2.0 with the current version you downloaded.

The command above will start the Selenium Grid Hub as a localhost server on port 4444, which you can alter by using the -host parameter in the command above.

Accessing the Grid console

The Grid exposes the server’s numerous configuration details on the web page when you browse http://localhost:4444/grid/console.

On this page, you’ll see the link “View config” which will take you to a page with more information about the current hub’s settings.

Configuring a new node

With the steps we’ve done thus far, we’ve only managed to get one node up and running. We need to register a new port to build extra nodes. Therefore type the following command in the terminal:

java -jar selenium-server-4.2.0.jar -role node -hub http://localhost:4444/grid/register -port 5555

The grid allows for five Chrome, five Firefox, and one Internet Explorer browser by default. To change this, add -browser “browserName=browser name>,version=browser version>,maxInstances=maximum instances of the browser>,platform=platform name>” to the command.

For example, on a Windows operating system, we may use the following command to allow only one instance of Firefox:

java -jar selenium-server-4.2.0.jar -role node -hub http://localhost:4444/grid/register -port 5555 -browser "browserName=firefox,maxinstance=1,platform=WINDOWS"

You’ll see that just one instance of Firefox is visible when you go to https://localhost:5555/grid/console.

The Grid hub and node machines should now be configured and ready for use. To execute test scripts on node machines, you can use an IDE like Eclipse or IntelliJ and create WebDriver code.

Selenium test scripts are distinct from other test framework script patterns, and the creators have provided guidelines detailing how to construct a functional, successful Selenium test script.

You can read the official documentation to learn more about writing test scripts for Selenium Grid nodes.

Conclusion

After reading this article, I hope you will understand the concept of cross-browser testing and start implementing it.

Understanding and utilizing Selenium Grid requires some expertise, but using it can improve the efficiency and speed of your tests and the scalability of your applications/products as long as you’re comfortable with building and maintaining the underlying infrastructure yourself.

Try Reflect: A modern cross-browser testing platform

Reflect is a no-code testing platform that lets you build and run tests across all popular browsers. Instead of building and maintaining your own infrastructure, using a cloud platform like Reflect allows you to get the benefits of automated cross-browser testing without the headache of maintaining an entire testing grid yourself.

Try it for free.

Get started with Reflect today

Create your first test in 2 minutes, no installation or setup required. Accelerate your testing efforts with fast and maintainable test suites without writing a line of code.

Copyright © 2022 Reflect Software Inc. All Rights Reserved.