LambdaTest Community

Find answers, support, and inspiration from other users

LambdaTest Community

How do I setup selenium grid for parallel execution in different browsers?

I want a step by step tutorial on how do I setup selenium grid for parallel execution in different browsers, can anyone please provide it to me.

Up Vote Down Vote 0 Votes
Posted 4 months ago


Original Source - LambdaTest

Selenium is by far the most used web automation testing tools. One of the reasons behind this huge popularity is Selenium’s automated cross browser testing capabilities. Selenium automation testing can help you test on all major browsers, all major operating systems, and even on mobile device browsers. You can get a huge browser coverage in all your functional tests ensuring the perfect experience for a wide range of your potential users.

But there is a challenge. You can load only so many different browsers on your local machine. For example, if you have a windows machine, you cannot test on Safari browsers, similarly, if you have a Mac machine you won’t be able to test on IE or Edge browsers. In addition, running tests on a single machine was a time-consuming process. If you have multiple computers, why test on a single one at a time?

The ideal scenario would be to test on a network of interconnected machines having different browser environments running multiple tests cases concurrently, in parallel, and reducing the overall testing time by multiple folds. And here I am also including time taken for cross browser testing as well.

And that is exactly what Selenium Grid is built for. Unlike Selenium WebDriver which allows you to perform automated cross browser testing in a sequential manner, a Selenium Grid setup will allow you to run test cases in different browsers/ browser versions, simultaneously.

What Is Selenium Grid?

Before we start with Selenium Grid setup, it is necessary to realize the basics of a Selenium Grid.

So, the Selenium Grid basically allow us to run our automated tests on different operating systems against different browsers. And that too in a parallel manner. Selenium automation testing tool will help you with faster automated cross browser testing, along with efficient utilization of in-house hardware.

Selenium Grid is comprised of two concepts:

Hub: It is the center of the Selenium Grid setup architecture that manages the network of the test machines. There is only one hub in a network which is assigned to a test of DesiredCapabilities(operating system, browser, browser versions) and then the hub finds the test that matches the given configurations.

Node: Nodes are the test machines that execute the test that was earlier loaded on the hub. There can be multiple nodes configured with a different operating system and different browsers. It is not mandatory for the node to run on the same platform on which the hub is running.

Infrastructure to configuring a Selenium Grid setup for parallel execution involves just two steps:

  1. Creating a hub.
  2. Defining the nodes and connecting to that hub.

Using Command Prompt For Selenium Grid Setup

The first step of a Selenium Grid setup would be to create a hub. You would have to make sure that your system has Java Runtime Environment (JRE) or better yet Java Development Kit (JDK) installed. Though most people recommend going for the latest JDK, I prefer an earlier tried and tested versions like JDK SE 08 or 09. You can go for the latest one if you wish. Here are the next steps –

  • Download and extract Selenium Standalone server JAR files. You can download them from here.
  • Next, open a command prompt or terminal and navigate to the directory where the Selenium Standalone Server jar file is saved.
  • Run the command “java -jar selenium-server-standalone-3.141.59.jar -role hub”. This command would launch a Selenium Grid hub on port 4444 by default. You can also check the same by directing to http://localhost:4444/grid/console.

Since the hub has already been created, the next step to Selenium Grid setup for parallel execution would involve launching a node. You start with going to the other machines where we want to setup nodes. Again, these machines should have a JDK/JRE setup.

In the node machine, open a command prompt or terminal and navigate to the directory where you have saved the browser driver files.

Enter the below command in order to configure Chrome driver in your Selenium Grid setup for parallel execution.

  • In the above command I have used my machine IP along with the port 4444 where the hub is actually running. I have also selected the port 4546 where I want my node to get registered. You can opt for any free port for registering the node.

Similarly, you can register other nodes for other browsers. For example, here’s how you can configure Firefox(Gecko) driver and Internet Explorer driver to your Selenium Grid setup for parallel execution.

Configuring Firefox(Gecko) driver in Selenium Grid setup:

Note: Please make sure that you select different ports for different nodes to connect with the single hub running on port 4444. Also, before running your test on IE, make sure that the browser zoom is exactly 100% otherwise it might show an error.

You can notice by above commands that we are running our first node for chrome driver on port 4546, the second node for firefox driver is running on port 5566, and the third node for IE browser is running on port 4547. Here is the output screenshot for further reference:

Now, that we have our Selenium Grid setup configured, your next step is to perform Selenium automation testing for your cross browser testing suite.

Execute Automation Testing With Selenium Grid For Parallel Execution

It is time for some automated cross browser testing! I will be running an automation script demonstrating the Selenium Grid for parallel execution. This script would run parallelly on Chrome, Firefox, and Internet Explorer which are registered on different ports and attached to a single hub.

Here is the sample code I used to perform automation testing with Selenium Grid for parallel execution in different browsers.

Above is the java class file that is configured with the XML file which includes the values of parameters passed in the java file and also helps in creating a suite of different classes that would run in a parallel manner.

Read more - How to Setup Selenium Grid For Parallel Execution In Different Browsers | LambdaTest

Up Vote Down Vote 0 Votes
Posted 4 months ago
1 Answer
4 months ago