Sunday, March 25, 2012

Selenium-Grid2 with TestNg

-------
HUB :- Needs to be use seperate cmd Promt for each hub,FF,Chrome,IE
-------
1. Selenium-server-sandedalone 2.19.0

2. Chrome Driver

thall all available here http://code.google.com/p/selenium
/downloads/list

strat the hub:-
--------------
java -jar selenium-server-standalone-2.19.0.jar -role hub

Note: we able to see the Console : http://localhost:4444/grid/console

Strat the firefox:-
-----------------
java -jar selenium-server-standalone-2.19.0.jar -maxSession=5 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=firefox,maxInstances=5
-port 5556

note : maxSession and maxInstances Optional. if we are not mentioned it will use the Default.

Start the chrome:-
-----------------
java -Dwebdriver.chrome.driver=C:
\Users\Reva\Desktop\SeleniumG
rid\chromedriver.exe
-jar selenium-server-standalone-2.19.0.jar -role webdriver
-hub http://localhost:4444/grid/register -browser browserName=chrome,platform=WINDOWS -port 5557

Note:- Chrome Driver Path (in my case) C:\Users\Reva\Desktop\SeleniumGrid\chromedriver.exe

Start the IE:-
--------------
java -jar selenium-server-standalone-2.19.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5557

Note:- Port number by default:5555, BRoWSER NAME and PlATFOM MUST match with the JAVA Code Capability.setBrowserN
ame, Capability.SetPlatform (for the Chrome and FF Platform is Optional. if we given, need to be specify in java code as well ( Exactly).

---------
JAVACODE:-
---------
HERE I given the Two Parameters one is browser and second one is port:4444

@Parameters({"browser", "port"})
@Test
public static void intselenium(String
browser, String port) throws MalformedURLException, InterruptedException
{

DesiredCapabilities capability= new DesiredCapabilities();

if (browser.equalsIgnoreCase("firefox"))
{
capability.setBrowserName(browser);
}

if (browser.equalsIgnoreCase("iexplore"))
{
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capability.setBrowserName(browser);
}

if (browser.equalsIgnoreCase("chrome"))
{
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
capability.setBrowserName(browser);
}
try {

driver= new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capability);
selenium = new WebDriverBackedSelenium(driver, "URL");
driver.get("URL);
} catch (MalformedURLException e) {

e.printStackTrace();
}
}

-------
TestNG:-
-------




























----------------------------
Default JSON Configuration:-
----------------------------

By default the grid will start with a default set of browsers, 5 Firefox, 5 Chrome, 1 IE - you can change this configuration by supplying command line options when you start the node server

{
"capabilities":
[
{
"browserName":"firefox",
"maxInstances":5
},
{
"browserName":"chrome",
"maxInstances":5
},
{
"browserName":"internet explorer",
"version":"7",
"platform":"WINDOWS",
"maxInstances":1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
"maxSession":5,
"url":"http://192.168.102.130:5555/wd/hub",

}
}

---------------------------------
Start Configured Json Run using:-
---------------------------------

java -jar selenium-server-standalone-2.0rc3.jar -role webdriver -nodeConfig myconfig.json -hub http://127.0.0.1:4444/grid/register

No comments:

Post a Comment