Adding nodes to Selenium Grid for cross-browser testing

In this recipe, we will add nodes to the Selenium Hub that we set up in the previous recipe. We will use multiple OS platforms and browser combinations for cross-browser testing

How to do it...

We will add nodes with the following OS and browser configurations to the Hub:

Adding an IE node

Let's begin with a node which provides Internet Explorer capabilities to run on Windows. Open a new command prompt or terminal window and navigate to the location where Selenium server jar is located. To launch and add a node to the Grid, type the following command:

java -Dwebdriver.ie.driver="C:SeDriversIEDriverServer.exe" -jar selenium-server-standalone-2.46.0.jar -role webdriver -browser "browserName=internet explorer,version=10,maxinstance=1,platform=WINDOWS" -hubHost 192.168.1.103 –port 5555

To add a node to the Grid, we need to use the –role argument and pass webdriver as the value. We also need to pass the browser configuration for the node. This is passed through the browser argument. In this example, we passed browserName as internet explorer, the version as 10, maxinstance as 1, and platform as WINDOWS. The maxinstance value tells the Grid how many concurrent instances of the browser will be supported by the node.

To connect the node to the hub or Grid server, we need to specify the –hubHost argument with the hostname or IP address of the Grid server. Lastly, we need to specify the port on which the node will be running.

When we run the preceding command, and after the node is launched, the following configuration will appear in the Grid console:

Adding an IE node

Alternatively, a node can be added by creating a configuration file in the JSON format and then using the following command:

{
  "class": "org.openqa.grid.common.RegistrationRequest",
  "capabilities": [
   {
   "seleniumProtocol": "WebDriver",
   "browserName": "internet explorer",
   "version": "10",
   "maxInstances": 1,
   "platform" : "WINDOWS"
   }
  ],
  "configuration": {
   "port": 5555,
   "register": true,
   "host": "192.168.1.103",
   "proxy": "org.openqa.grid.selenium.proxy.
   DefaultRemoteProxy",
   "maxSession": 2,
   "hubHost": "192.168.1.100",
   "role": "webdriver",
   "registerCycle": 5000,
   "hub": "http://192.168.1.100:4444/grid/register",
   "hubPort": 4444,
   "remoteHost": "http://192.168.1.102:5555"
  }
}

We can now pass the selenium-node-win-ie10.cfg.json configuration file through command-line arguments, as shown in the following command:

java -Dwebdriver.ie.driver="C:SeDriversIEDriverServer.exe"-jar selenium-server-standalone-2.46.0.jar -role webdriver -nodeConfig selenium-node-win-ie10.cfg.json

Adding a Firefox node

To add a Firefox node, open a new command prompt or terminal window and navigate to the location where the Selenium server JAR file is located. To launch and add a node to the Grid, type the following command:

java -jar selenium-server-standalone-2.47.1.jar -role webdriver -browser "browserName=firefox,version=38.0.5,maxinstance=2,platform=WINDOWS" -hubHost localhost –port 6666

In this example, we set maxinstance to 2. This tells the Grid that this node will support two instances of Firefox. Once the node is started, the following configuration will appear in the Grid console:

Adding a Firefox node

Adding a Chrome node

To add a Chrome node, open a new command prompt or terminal window and navigate to the location where the Selenium server jar is located. To launch and add a node to the grid, type the following command:

java -Dwebdriver.chrome.driver="C:SeDriverschromedriver.exe" -jar selenium-server-standalone-2.47.1.jar -role webdriver -browser "browserName=chrome,version=35,maxinstance=2,platform=WINDOWS" -hubHost localhost -port 7777

Once the node is started, the following configuration will appear in the Grid console:

Adding a Chrome node

Mac OS X with Safari

We added IE, Firefox, and Chrome instances on a Windows machine. Let's add a Safari node from a Mac OS. Open a new terminal window and navigate to the location where Selenium server jar is located. To launch and add a node to the Grid, type the following command:

java -jar selenium-server-standalone-2.47.1.jar -role webdriver -browser "browserName=safari,version=7,maxinstance=1,platform=MAC" -hubHost 192.168.1.104 -port 8888

Once the node is started, the following configuration will appear in the Grid console:

Mac OS X with Safari
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.115.155