You are using an older browser that might negatively affect how this site is displayed. Please update to a modern browser to have a better experience. Sorry for the inconvenience!

Execution of Test in Remote Machine using Selenium Grid


What is Selenium Grid, It is a new concept introduced by Selenium team to run Tests in remote machines by executing the tests across different OS, different browsers and different machines.

This is an enhancement to the Selenium Web driver. Grid uses Web driver code for executing the test scripts.

http://grid.selenium.googlecode.com/git-history/22ed3ff910401af083bf06a4d13514f4c6a623ca/src/main/webapp/how_it_works.html

The Grid contains a single Hub and one or more nodes.

Hub:

  • It is a centralized place to which all other nodes are connected.
  • There will be only one Hub.
  • Tests will be loaded and executed in the Hub.

Node:

  • A device, connected with the Hub. A node may be a Mobile or Tablet or Laptop or Computer which different Operating Systems, and browsers.
  • Number of nodes will vary depending upon the testing requirements.
  • Execution of tests will be displayed in Nodes.

Use of Selenium Grid:

  • It is used to execute tests across multiple platforms.
  • It reduces the execution time of the Tests.

Installation Process:

  1. Download Selenium Server from the official site: http://docs.seleniumhq.org/download/
  2. Place the downloaded .jar file in any of the local drive (C or D or E drive) in both Hub and Node machines.
  3. Install Selenium Web driver in the Hub machine.

Below is the link for setting up Selenium Grid

http://docs.seleniumhq.org/docs/07_selenium_grid.jsp

Setting Up A Grid:

  1.  On Hub machine, Enter the following command in the ‘Command Prompt’,

F:\java -jar selenium-server-standalone-2.43.1.jar -role hub

Note:

Here, Downloaded .jar file (selenium-server-standalone-2.43.1.jar) is placed in F:/

  1.    Now, open a browser window and enter the following linkhttp://localhost/grid/console in order to check whether the Hub is configured or not.
  2.    On the Node machine, enter the following command in the ‘Command Prompt’,

F:/ java -jar selenium-server-standalone-2.43.1.jar -role webdriver -hub http://

100.00.0.7:4444/grid/register -port 5566

Note:

Here, Downloaded .jar file (selenium-server-standalone-2.43.1.jar) is placed in F:/

In the above command, replace your Hub IP-Address highlighted IP-Adin yellow.

Repeat the same process for connecting multiple Nodes with the Hub.

  1.     Now, open a browser window and enter the following linkhttp://localhost/grid/consolein order to check the Nodes that are connected. Nodes connected with the Hub are highlighted in below image
  2.    Below is the sample code for executing the test in multiple browsers like IE, Firefox, and Chrome.

Internet Explorer:

String nodeURL1 = “http://10.0.0.7:4444/wd/hub“;
System.setProperty(“webdriver.ie.driver”,”F:\\IEDriverServer.exe”);
DesiredCapabilities capability1 = DesiredCapabilities.internetExplorer();
capability.setBrowserName(“internet explorer”);
capability1.setPlatform(Platform.WIN8_1);
driver = new RemoteWebDriver(new URL(nodeURL1), capability1);
driver.get(“http://www.google.com“);

FireFox:

String[] nodeURL = {“http://10.0.0.4:5566/wd/hub“} ;
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName(“firefox”);
capability.setPlatform(Platform.WIN8_1);

driver.get(“http://www.google.com“);

Chrome:

String nodeURL1 = “http://169.254.111.81:1339“;
System.setProperty(“webdriver.chrome.driver”,”F:\\chromedriver.exe”);
DesiredCapabilities capability1 = DesiredCapabilities.chrome();
capability1.setBrowserName(“chrome”);
capability1.setPlatform(Platform.WIN8_1);
driver = new RemoteWebDriver(new URL(nodeURL1), capability1);
driver.get(“http://www.google.com“);

  1.     Execute the Test suite available in Hub machine.
  2.      Results would be displayed in Node machine, Refer below three images respectively.

Note:

Similarly, we can run other browsers/devices by using the corresponding Drivers.

Reference link:  https://code.google.com/p/selenium/wiki/Grid2