How To Set up Cross Browser Testing With Selenium Grid

Developed by Jason Huggins in 2004, Selenium has quite quickly gained its popularity for being an impressive open-source test automation framework. With the ability to support major web browsers such as Chrome, Firefox, Safari, Internet Explorer, multiple languages such as Java, PHP, Python, Ruby, C#, and platforms such as iOS, Windows, and Linux, it has transformed the testing landscape.

Selenium framework has four different types of tools that help with the tests, which are Selenium Integrated Development Environment, Selenium WebDriver, Selenium RC, and Selenium Grid. Here’s a little more about Selenium Grid, its uses, and how you can set up cross browser testing with it.

What is a Selenium Grid?

While Selenium itself solves the problem of spending too much time and effort on manual testing by automating the whole process, it can still be a time-consuming affair to run test scripts on various platforms, devices, and browsers one by one. Finding a solution for this led to the invention of Selenium Grid by Patrick Lightbody, who initially created a feature by the name Hosted QA. This feature was helpful in running test scripts across multiple platforms, devices, and browsers simultaneously. And this feature was later renamed as Selenium Grid. And with this, it became possible to save way more time while running test scripts.

Components of Selenium Grid

Before you know how to set up cross browser testing with Selenium Grid, it is important to know what all the components of it are and what its purpose is. Selenium grid hub is a centralized unit that acts as the receptor for all the test requests coming from clients. These requests are then sent to the specific nodes as per the capabilities. Selenium grid allows you to use one hub because it is a centralized system. The second component of a Selenium Grid is Selenium Grid Node, which fulfills the function of receiving test requests from the hub. There are several nodes in a single grid, and these nodes have different capabilities. Now that you know what the components of Selenium Grid are, here are the steps involved in setting up cross browser testing with Selenium Grid.

Steps for Selenium Grid Setup

  • Installing Java and Configuration of Environment Variables

The main prerequisite to using Selenium Grid for running tests is to have Java already installed in your system. If you already have Java installed in your system, you can move on to the next sub-step of this step. Besides Java, another prerequisite for using Selenium Grid is having a Selenium server installed on your device. Selenium server is a collection of files, which is known as jar files collectively. And the reason why you need java is that these jar files can only be used when you have this programming language on your device.

  • Selenium Server Installation and Download

You will easily find the link to download jar files for the Selenium server on the internet. While there is no specification as to where you can save the jar files for best results, it is recommended that you save it in the C drive so that all the subsequent files also get saved in the same drive, which helps maintain consistency across nodes and hubs on your device. Now that you have Java as well as Selenium server on your device, you are ready to proceed to the next step of the setup.

  • Hub Machine Configuration

The next step involves the configuration of the hub machine, and to initiate this, you can click on start and then go to the command option. Go to the location of the jar files of your selenium server and enter this command— java -jar selenium-server-standalone-3.141.59.jar -role hub. While this command can be used for the latest version of the Selenium server, you can change the version serial number in your command if you wish to use a different version.

  • Selenium Grid Node Configuration

Now, go back to the command option again and go to the location of server files. Enter this command— java -jar selenium-server-standalone-3.141.59.jar -role node -hub https://192.168.0.4:4444/grid/register -port 5555. If you have to use multiple nodes, all you need to do is register every node with the hub by entering the same command.

These are the steps involved in setting up your Selenium grid for running cross browser testing. Being an extremely powerful framework, be assured that you will be able to save a significant amount of time and run tests without having to worry about errors. Once you get the hang of setting up and using Selenium, it becomes almost effortless to run tests.