How To Setup Selenium Grid In Selenium Testing Automation

Problem
If you have a very long selenium testing script which will execute about 1000 minutes, what will you do? Will you just wait for one day for the test result? The answer is No, It is so inefficiency .

Solution
We can use Selenium Grid to resolve this problem. First you need to separate the long testing script into 10 short ones. And each short testing script will just run 100 minutes. This is acceptable. Then we can execute the 10 short ones in multiple physical or virtual machines with multiple different web browser versions at the same time. After doing that you just need to wait about 100 minutes to get and debug the test results. This can greatly shorten the test time.

Selenium Grid Introduction
A selenium grid includes a single hub and at least one node.
selenium grid structure

Hub is the center of selenium grid. It receives all the requests from testing script. The request include the information that the test need to run with, such as the platform ( Windows, MacOS, Linux, iPhone, iPad, Android device etc), the browser type and version. When the hub receive a request, it will distribute the request information to the node to run the test.

Before continue, you should confirm following 2 things.
Confirm that you had installed jdk correctly and set JAVA_HOME environment variable.
Confirm that you download the correct selenium standalone server and save it in a local folder.

How to start the Hub?
1. Open your dos or shell window.
2. Go to the folder where you save the selenium jar file.
3. Run below command in the window.

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

start selenium hub in selenium grid

You can see that the Hub started as a server and listening on port 4444. This is the default port for it. You will locate it by using this port number in the Hub locating URL in your java code later. To change the port number, you can use -port parameter in the command line.

java -jar selenium-server-standalone-2.53.0.jar -role hub -port 8888

You can go to server status page using following URL http://localhost:4444/grid/console. You should use the port number which you set when you start it if you do not use the default port number 4444. selenium hub server status page

READ :   Setup Selenium Grid With Docker

You can click the view config link to see detail config information for the Hub.
detail config information for selenium grid hub

Nodes are the physical or virtual machines that really run the test script. Node must be register to Hub before it can run.

Following command can startup a Node and register it to the Hub. If not specify the -port parameter, the Node will listen on 5555 port by default. Execute below command in a different Dos or Shell window other than the Hub dos window.

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

start a node in selenium grid

After register a Node, you can see the Node info in following page. http://localhost:4444/grid/console

selenium node info console page
Now the Selenium Gird has been setup, there is one Hub and One Node register to it. Hub manage and scan the status of all it managed Nodes. If you close the Node for sometime, then the Hub will unregistered the Node automatically. You can see the unregistered log in dos window.

From above picture you can see When a Node started, it will initiate 11 browsers ready for you to use by default. 5 Chrome, 5 Firefox and 1 Internet Explorer. You can use those browsers either through Selenium RC or Selenium Webdriver.

When you hover your mouse on an web browser icon in above picture, the tips like following.

selenium grid node status info firefox web browser info

{seleniumProtocol=Selenium, browserName=*firefox, maxInstances=5, platform=VISTA}

seleniumProtocol=Selenium : This browser can used by Selenium RC.
browserName=*firefox : This is a firefox web browser.
maxInstances=5 : The maximum instance of this browser is 5.
platform=VISTA : This web browser runs on windows Vista.
{seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platform=VISTA}

seleniumProtocol=WebDriver: This browser can used by WebDriver.
browserName=chrome: This is a google chrome web browser.
maxInstances=5 : The maximum instance of this browser is 5.
platform=VISTA : This web browser runs on windows Vista.

We will show you how to use Selenium Grid to run testing script in multiple Node concurrently in next article.

(Visited 550 times, 1 visits today)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.