Home > Automation Testing > Advance Selenium > Selenium Grid Setup Run Scripts on multiple machines

Selenium Grid Setup Run Scripts on multiple machines

This post was most recently updated on July 31st, 2024

Selenium Grid allows to run tests in parallel mode on different machines and different browsers available on that machines. Selenium grid working is based on Master Slave architecture.

Main Components of Selenium Grid are:
1. Hub: Hub acts as a master in Selenium Grid. There will be a single hub in the grid which will know the configuration of each registered node. When specific test requirements are given to the hub, then hub searches for the node which matches the test requirements. If hub founds a node which matches the test requirements, then test will be executed on that node machine. If node with required specifications is not found then hub returns an error.

2. Node: Node acts as slave in Selenium Grid. There can be one or more nodes present in the Grid. Node machines can have different configuration like OS, different versions of browsers etc… It is not mandatory for a node to have same configuration like that of hub machine. Nodes are dependent on Hub.

Steps to Configure Selenium Grid:

There are 3 major steps in configuration of selenium grid
1. Configuring Hub machine
2. Configuring Node machine
3. Executing script

Image: Selenium standalone server download location

1. Configuring Hub machine:
a. Download Selenium server jar file from this location on the hub machine.

b. Create a ‘Selenium server’ folder on C drive and keep the jar file inside this folder.
(Note: User can keep the ‘Selenium server jar file’ at any desired location.)

Image: Selenium server standalone saved locally

c. Open Command Prompt and navigate to Selenium server jar file location. Once navigated to Selenium sever jar file location, give the below command in the command prompt:

java -jar selenium-server-standalone-3.141.59.jar -role hub 

Once the above command is executed the selenium server starts and hub will be launched on the machine. Below is the screenshot of the command prompt when above command is executed.

Image: Selenium hub started

Whether hub is up and running can be validated by navigating to: http://localhost:4444 

Note:

  1. Be careful to change the ‘selenium server standalone jar file’ version accordingly. 2.
  2. By default port ‘4444’ is assigned to the web interface by Selenium Grid. If this port is already assigned or we want to use any other port then following command can be used: java -jar selenium-server-standalone-3.141.59.jar -port 4455 -role hub.

2. Configuring Node machine:
a. Download Selenium server jar file from this location on the node machine also.

b. Create a ‘Selenium server’ folder on C drive and keep the jar file inside this folder.
(Note: User can keep the ‘Selenium server jar file’ at any desired location.)

c. Open Command Prompt and navigate to Selenium server jar file location. Once navigated to Selenium sever jar file location, give the below command in the command prompt:

java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.0.17:4444/grid/register

Note: In place of ‘192.168.0.17’ user can write the IP address of the his/her own machine

d. Once the above command is fired then something similar to below screenshot will be seen in the command prompt

e. Now on the hub machine open any browser and navigate to http://localhost:4444/grid/console. Once navigated to the url, hub will display the nodes connected to it and all required information of the nodes. For example, in the below screenshot one node with id: ‘192.168.0.39’ can be seen connected to the hub. All the required information of the node machine such as different browsers, IP address of the node machine, OS of the machine etc.. is displayed on the console. From the node machine which is connected to hub, by default 5 firefox browsers, 5 chrome browsers and 1 IE browser can be used.

Image: Status of node connected to Selenium hub

From the above screenshot, we can see current node machine has by default 5 firefox browsers, 5 chrome browsers and 1 IE browser.

3. Executing script: Below is the sample code, if this code is executed on the hub machine then script will run on node machine.

Decoding the script:

a. Using Desired capabilities we have set the platform and browser on which we want to execute the code

b. Here we have to use Remote Web Driver to access the url. Remote Web Driver also accepts the Desired capabilities

Note:

  1. Here, user should make sure that chromedriver version is same on hub and node machines. In case we are using firefox browser then geckodriver version should be same.
  2. Suppose, many nodes are connected to the hub, then hub decides on which node the script should be executed. Through Desired Capabilities user will give the specific requirements on which machine the script should run.
This Article is TAGGED in . BOOKMARK THE permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">