Selenium Grid Infrastructure Setup for Mobile and Desktop Browsers

Selenium Grid Introduction

Selenium-Grid is used to run parallel executions in multiple machines at the same time, and to run Selenium WebDriver tests in parallel, we need to set up the Selenium Grid Server as a hub.

Hub will provide the available capabilities to the webdriver and the registered nodes will connect to hub for parallel execution. Selenium Grid supports multiple operating systems like Windows, Mac, Linux and iOS. It also supports several browsers such as Chrome, IE, Firefox, Opera, Safari, and Android.

The Hub acts as a bridge, which receives the test execution request and distributes it to the available nodes or keeps them in queue until any stop sending or receiving requests from hub.
To Exemplify, if you have a suite of 11 tests, but you set up Selenium-Grid to support 10 different machines (VMs or separate physical machines) to run those tests, it will distribute maximum 10 test suites in 10 different nodes; however, it will keep 1 node in queue for execution.

For large test suites and to verify large amounts of data-validation in lesser time, Selenium Grid is the best approach to save time and human efforts. In practicing agile software development, results can be shared by overnight execution of test suite.

Steps to set up the Selenium Grid

1. Install java from https://java.com/en/download/manual_java7.jsp

Verify “java -version” from the command line

IMG1

 

2. Download the latest Selenium Server standalone JAR file from http://www.seleniumhq.org/download/

Hub Configuration

Create a batch file to run the hub (open a new text document, put the below code lines in it and save it as a .bat extension and then launch the hub batch file.

IMG2

Note: Set the path for Selenium-Server-Standalone jar file and run the batch file to launch hub.

This will start the hub server through command prompt and starts listening to node with default port 4444.

IMG3

To access grid console; open any browser and access link – http://localhost:4444/grid/console or http://:4444/grid/console. It will display the following information in the browser:

Selenium Grid

To view the node config details, click on “view config” link as displayed in above grid console snapshot.

Node Configuration

Node Configuration using Batch File:

Create a batch file to run the node (open a new text document, put the below code lines in it and save it as a .bat extension and then launch the node batch file.

In below snapshot we have registered a node in Windows machine for browser – Internet Explorer 11.

Image4

For Instance, below we have created 2 more nodes registering with hub which includes Firefox and Chrome browsers with their respective batch files snapshot in local repository.

IENode FFNode ChromeNode IMG6

Post to completion of all nodes configuration, we can view config in grid console as displayed in below screenshot.

Grid-console

Node Configuration using JSON File:

For Windows

  • Create a notepad file with all below listed configuration details and save it as *.json.
{
"capabilities":
                [
                {
		   "platform": "WINDOWS",
                                "browserName": "chrome",
                                "maxInstances": 3,
                                "seleniumProtocol": "WebDriver"
                },
                {
		    "platform": "WINDOWS",
                                "browserName": "firefox",
                                "maxInstances": 2,
                                "seleniumProtocol": "WebDriver"
                },
				{
		    "platform": "WINDOWS",
                                "browserName": "internet explorer",
                                "maxInstances": 1,
                                "seleniumProtocol": "WebDriver"
                }
                ],
  "configuration":
                {
                                "cleanUpCycle": 5000,
		"registerCycle": 5000,
		"nodeTimeout": 120,
                            "timeout": 600000,
		"nodePolling": 2000,
		"hub": "http://localhost:4444/grid/register",
                          "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
                          "maxSession": 10,
                           "port": 5555,
                            "host": "localhost",
                            "register": true,
                           "hubPort": 4444,
                            "hubHost" :"localhost",
		   "role": "node"
                }
}

Now create batch file for windows and give path for above json file so that it can execute through json.

Img7

Here is the view of grid config file:

 Selenium Grid

 

Configure Android Node in Windows

Download Android SDK for Windows from https://developer.android.com/sdk/index.html?hl=i

Download Brackets (adb bundles) Packages from http://brackets.io/

* Set ANDROID_HOME= Android PATH (D:\adt-bundle) in Environment Variables.

* Set Path for platforms, platform-tools and tools (D:\adt-bundle\…).

NOTE:

* Configuration done only for Android Chrome browser.

* Enter paths for all above folders separately in Environment Variables.

* Connect device with machine and open terminal.

* Enter adb devices (Use this command to connect android device).

Selenium Grid

* Set the capabilities and pass some parameters which identify the capability for android-chrome. For instance: ‘version’ (We can put any string value for version).

case "windows-android-chrome":
			case "windows-android_chrome":
			case "mac-android-chrome":
			case "mac-android_chrome":
				objCapabilities = null;
				objCapabilities = DesiredCapabilities.chrome();
				chromeoptions = new ChromeOptions();				
				chromeoptions.setExperimentalOption("androidPackage", "com.android.chrome");
				objCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeoptions);
				objCapabilities.setCapability("platform", "WINDOWS");
				objCapabilities.setCapability("browserName", "chrome");
				objCapabilities.setCapability("version", "android");

				if(osname.toLowerCase().contains("windows")){
					ChromeDriverPath = System.getProperty("user.dir") + "/Tool/chromedriver.exe";
				}else{
					ChromeDriverPath = System.getProperty("user.dir") + "/Tool/chromedriver";
				}
				System.setProperty("webdriver.chrome.driver", ChromeDriverPath);

To view the Selenium-Grid Console for android-chrome with version value as mentioned in previous step.

Selenium Grid

iOS

Appium_iPad_Simulator

{
    "capabilities": [
        {
            "browserName": "iPad-Simulator",
            "version": "7.1",
            "maxInstances": 1,
            "platform": "MAC"
        }
    ],
    "configuration": {
        "cleanUpCycle": 2000,
        "timeout": 300000,
       "browserTimeout": 60000,
        "hub": "http://localhost:4444/grid/register",
        "host": " localhost ",
        "maxSession": 1,
        "port": 4730,
        "hubPort": 4444,
        "hubHost": " localhost ",
        "url": "http:// localhost:4730/wd/hub",        
        "register": true,
       "registerCycle": 5000,
        "role": "node"
    }
}


Command file used to execute iPad in Mac Machine through JSON

#!bin/sh
cd /Users/admin/Desktop/Mindoro_Automation
appium -p 4730 --nodeconfig /Users/admin/Desktop/Mindoro_Automation/appiumgrid_iPad-Simulator1.json 

Appium_iPhone_Simulator

{
    "capabilities": [
        {
            "browserName": "iPhone-Simulator",
            "version": "7.1",
            "maxInstances": 1,
            "platform": "MAC"
        }
    ],
    "configuration": {
        "cleanUpCycle": 2000,
        "timeout": 300000,
      "browserTimeout": 60000,
        "hub": "http://localhost:4444/grid/register",
        "host": " localhost ",
        "maxSession": 1,
        "port": 4729,
        "hubPort": 4444,
        "hubHost": " localhost ",
        "url": "http:// localhost:4729/wd/hub",        
       "register": true,
       "registerCycle": 5000,
        "role": "node"
    }
}

Command file used to execute iPhone in Mac Machine through JSON

#!/bin/sh
cd /Users/admin/Desktop/Mindoro_Automation
appium -p 4729 -- nodeconfig /Users/admin/Desktop/Mindoro_Automation/appiumgrid_iPhone-Simulator1.json 

Safari

NOTE: If safari does not launch through grid or throws an error then might we required a safari plugin from selenium-server-standalone jar file and import it manually in safari browser.

{
"capabilities":
                [
		{
		    "platform": "MAC",
                                "browser": "safari",
                                "maxInstances": 1,
                                "seleniumProtocol": "WebDriver"
                }
                ],
  "configuration":
                {
                                "timeout": 300000,
		      "hub": "http:// localhost:4444/grid/register",
                                "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
                                "maxSession": 1,
                                "port": 5557,
                                "host": " localhost ",
                                "register": true,
                                "hubPort": 4444,
                                "hubHost" : "localhost",
		      "role": "node"
                }
} 


Command file used to register Safari through terminal in Mac

#!/bin/sh
cd java -jar selenium-server-standalone-2.42.0.jar -role node –nodeConfig //selenium-node-macSafari.cfg.json

NOTE: Once all nodes get configured and registered with hub, it displays as below snapshot in grid console.

Grid-console-2

 

Terminologies used in Grid Configuration

role = When launching a node, it will forward the parameter to server on the node like, -role node.

host = Though it not needed and determined automatically. For some network configuration, network with VPN, specifying the host might be necessary.

port = the port the remote/hub will listen on. Default to 4444.

throwIn Capability Not Present = Default value is true; if no proxy is currently registered hub will reject the test request. On contrast, the request queued until a node supporting the capability which is added to the grid.

new Session Wait_Timeout = Default to no timeout ( -1 )ms after which a new test waiting for a node to become available will timeout else test will throw an exception before starting a browser.

hubConfig = It defines the hub properties in JSON format.

nodeConfig = It defines the node properties in JSON format.

cleanupCycle = It will check the timeout thread in ms.

node Timeout = The timeout in seconds prior to hub automatically ends the test so that browser will be released for another test to run.

browser Timeout= The browser gets hang after defined timeout in ms.

hub = It used to post the registration request using url – <http://localhost:4444/grid/register>

proxy =This will be used to represent the node. By default org.openqa.grid.selenium.proxy.DefaultRemoteProxy.

maxSession = Maximum number of sessions to run multiple tests at same time independently in different browsers.

register Cycle = It defines how often registered node will try to register itself again in ms,however, without restarting the node command file.

nodePolling = How often the hub checks if the node is still alive in ms.

 

Heera Singh

Heera Singh

Module Lead Quality Assurance

Heera Singh is working as a Module Lead Quality Assurance at 3Pillar Global. He brings with him rich experience in the field of automation for web and mobile-based applications. He has expertise in various automation tools and has been extensively involved in designing/developing automation suite for Healthcare, Finance, Education, and Fitness related applications. He has good experience in both function automation as well as in performance automation. He likes the challenges and is passionate about learning new automation tools and technologies.

9 Responses to “Selenium Grid Infrastructure Setup for Mobile and Desktop Browsers”
  1. Rajeev on

    Nice end to end grid guide.

    Reply
  2. Prashant on

    Hi,
    what is the difference between – “host” and “hubhost” parameters provided in config json.

    Also how to register a node to my hub which is behind another hub. For Example I have a hub running locally (also some local nodes are registered to it) and i want to run my desktop tests on these local nodes but mobile tests on Sauce labs.
    How to go about it ?

    Reply
    • Lucia on

      Hello,
      “host” parameter especifies the IP of the node computer, while “hubhost” is the IP of the computer acting as the hub. When you run hub and node on the same computer, their values are the same.

      I would separate your mobile tests on Sauce Labs (different java class and even testng.xml file), as you need to connect to it supplying your credentials and the hub has a different URL to connect your RemoteWebDriver.

      For Android and iOS we use Appium, which lets you add nodes to the Selenium Grid and it is based on Selenium.

      Regards.

      Reply
  3. Hina Ahuja on

    Is there is any why to use Selenium grid for native mobile application especially for IOS.

    Reply
  4. Kallem Sandeep on

    Hi hope you are doing good.

    Can you please explain me for setting the Android real devices as a node to the selenium Hub.

    I successfully created selenium hub and some browsers as selenium node.But i unable to set android real devices as node.

    Can you please guide me in detail or briefly.?

    Reply
  5. i on

    Did IOS supports Grid did you try it

    Reply
  6. gourav on

    How can we configure the two devices?

    Reply
  7. Jones on

    I been searching for this for a pretty long time, Your post looks very informative and also easy. Thanks for sharing

    Reply
  8. sandeep on

    Hi
    i am trying to configure winium driver as node to Hub. can you please share the steps and command to get it done

    Reply
Leave a Reply

Related Posts

3 Topics We Should Be Talking About at BrainstormTech Our 3Pillar clients, regardless of industry, share one common trait - they need help strategizing, designing, and delivering revenue-generating digita...
4 Reasons Everyone is Wrong About Blockchain: Your Guide to ... You know a technology has officially jumped the shark when iced tea companies decide they want in on the action. In case you missed that one, Long Isl...
3 Cloud Optimization Projects That Will Pay for Themselves i... AWS introduced 1,430 new features and tools in 2017, including 497 in the 4th quarter alone. This means that it can be a challenge for even the mos...
The Connection Between Innovation & Story On this episode of The Innovation Engine, we'll be looking at the connection between story and innovation. Among the topics we'll cover are why story ...
Go Native (App) or Go Home, and Other Key Takeaways from App... I just returned from my first WWDC. I feel like I learned more in a week at Apple’s annual developer’s conference than I have in years of actually dev...