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
it is not connecting to the remote computer what to do,it is not showing any issue also please help me out from this
ReplyDeleteThanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium
ReplyDeleteSelenium is used in many IT companies due to its numerous advantages compared to other automation testing tools in the market. There is massive demand for automation testers to validate software and mobile applications across the world. Taking Selenium Course in Chennai
ReplyDeletewill assist aspirants to enter automation testing industry!!!
I have been reading your blog posts. You blog posts are awesome. They provide good and extremely information which is more valuable. Online selenium training in chennai is predominant famous for Selenium Automation Training and how to get the necessary knowledge about the technology and implement it in a effective way.
ReplyDeleteThank you for your information. It very nice article.
ReplyDeleteSelenium Training in Pune
Great one..Nice introduction about the selenium webdriver.it was really helpful for beginners.Thanks for this post..keep update best selenium training in chennai
ReplyDeletebest selenium training institute in chennai
Training with placement in chennai
Great Article
ReplyDeleteData Mining Projects
Python Training in Chennai
Project Centers in Chennai
Python Training in Chennai