Selenium Grid is a tool that dramatically speeds up functional testing of web-apps by leveraging your existing computing infrastructure. It allows you to easily run multiple tests in parallel, on multiple machines, in an heterogeneous environment.
Stop waiting hours to get the results of your web acceptance builds! Selenium Grid transparently distribute your tests on multiple machines so that you can run your tests in parallel, cutting down the time required for running in-browser test suites. This will dramatically speeds up in-browser web testing, giving you quick and accurate feedback you can rely on to improve your web application.
How to Configure Selenium GRID
1) Download latest Selenium-server-standalone-2.25.0.jar
2) Download TestNG (should have TestNG framework)
3) Download ChromeDriver.exe
Test Script
package testNG;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.Selenium;
import junit.framework.Assert;
public class Google {
private Selenium selenium;
@Parameters({"browser","port"})
@BeforeClass
public void beforeClass(String browser,String port){
DesiredCapabilities capability= new DesiredCapabilities();
capability.setBrowserName(browser);
try {
WebDriver driver= new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capability);
selenium = new WebDriverBackedSelenium(driver, "http://www.google.com");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test
public void search() {
selenium.open("/");
selenium.type("id=lst-ib", "testing");
selenium.click("//input[@value='Google Search']");
}
@AfterClass
public void afterClass(){
selenium.stop();
}
}
Create the TestNG.xml file by copying the below code:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="tests"
thread-count="5">
<test name="Selenium TestNG - 1">
<parameter name="browser" value="firefox" />
<parameter name="port" value="4444" />
<classes>
<class name="testNG.Google" />
</classes>
</test>
<test name="Selenium TestNG - 2">
<parameter name="browser" value="chrome" />
<parameter name="port" value="4444" />
<classes>
<class name="testNG.Google" />
</classes>
</test>
</suite>
Now run the Test Suite by right clicking the TestNG.xml file from eclipse
Just Before running the script you should run Selenium-Grid server
Selenium-Grid server
For Hub:
java -jar selenium-server-standalone-2.25.0.jar -role hub
For a firefox based node:
java -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556 -browser browserName=firefox
For Google-Chrome based node:
java -Dwebdriver.chrome.driver="C:\.......\chromedriver.exe" -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5555 -browser browserName=chrome
Stop waiting hours to get the results of your web acceptance builds! Selenium Grid transparently distribute your tests on multiple machines so that you can run your tests in parallel, cutting down the time required for running in-browser test suites. This will dramatically speeds up in-browser web testing, giving you quick and accurate feedback you can rely on to improve your web application.
How to Configure Selenium GRID
1) Download latest Selenium-server-standalone-2.25.0.jar
2) Download TestNG (should have TestNG framework)
3) Download ChromeDriver.exe
Test Script
package testNG;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.Selenium;
import junit.framework.Assert;
public class Google {
private Selenium selenium;
@Parameters({"browser","port"})
@BeforeClass
public void beforeClass(String browser,String port){
DesiredCapabilities capability= new DesiredCapabilities();
capability.setBrowserName(browser);
try {
WebDriver driver= new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capability);
selenium = new WebDriverBackedSelenium(driver, "http://www.google.com");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test
public void search() {
selenium.open("/");
selenium.type("id=lst-ib", "testing");
selenium.click("//input[@value='Google Search']");
}
@AfterClass
public void afterClass(){
selenium.stop();
}
}
Create the TestNG.xml file by copying the below code:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="tests"
thread-count="5">
<test name="Selenium TestNG - 1">
<parameter name="browser" value="firefox" />
<parameter name="port" value="4444" />
<classes>
<class name="testNG.Google" />
</classes>
</test>
<test name="Selenium TestNG - 2">
<parameter name="browser" value="chrome" />
<parameter name="port" value="4444" />
<classes>
<class name="testNG.Google" />
</classes>
</test>
</suite>
Now run the Test Suite by right clicking the TestNG.xml file from eclipse
Just Before running the script you should run Selenium-Grid server
Selenium-Grid server
For Hub:
java -jar selenium-server-standalone-2.25.0.jar -role hub
For a firefox based node:
java -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556 -browser browserName=firefox
For Google-Chrome based node:
java -Dwebdriver.chrome.driver="C:\.......\chromedriver.exe" -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5555 -browser browserName=chrome