Connecting Grid:
1. Start the Hub:
java -jar selenium-server-standalone-2.14.0.jar -role hub
The hub will automatically start-up using port 4444 by default
to change java -jar selenium-server-standalone-2.39.0.jar -role hub -port 4441
2.
Start the nodes
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://localhost:4444/grid/register
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://
localhost:4441/grid/register -nodecongig webconfig.txt -port 5556 http://
localhost:4441/grid/console -browser browserName=firefox,version=3.6,maxinstances=5,platform=WINDOWS -nodecongig webconfig.txt
java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -Dwebdriver.ie.dr
iver="C:\IEDriverServer.exe" -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://
localhost:4441/grid/register -port5557 -browser browserName=firefox -browser browserName=chrome -browser browserName=iexplorer nodeTimeout 300
3. Create script to run using
DesiredCapabilities capability = DesiredCapabilities.firefox();
and
Pass that into the RemoteWebDriver object:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
4. create a testng.xml file and keep the tests in there, and run test ng Suite
You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console
import java.net.MalformedURLException;
import java.net.URL;
//import net.sourceforge.htmlunit.corejs.javascript.ast.ThrowStatement;
//import org.apache.xerces.util.URI.MalformedURIException;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
//import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Grid_demo3 {
@Parameters("browser")
@Test
public void Google_Serach(String b) throws MalformedURLException {
//pass the browser in the search function and print
System.out.println(b);
//make desired capability to null and give if else conditions for multiple change of browsers
DesiredCapabilities cap = null;
if(b.equals("firefox")){
cap= DesiredCapabilities.firefox();
cap.setPlatform(Platform.ANY);
cap.setBrowserName("firefox");
}else if (b.equals("chrome")){
cap= DesiredCapabilities.chrome();
cap.setPlatform(Platform.ANY);
cap.setBrowserName("chrome");}
else if (b.equals("iexplore")){
cap= DesiredCapabilities.internetExplorer();
cap.setPlatform(Platform.WINDOWS);
cap.setBrowserName("iexplore");}
//no need to give path of chrome exe as we r giving it in node
//C:\Meeraja-Selenium\libraries>java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-serve
// r-standalone-2.39.0.jar -role webdriver -hub http://localhost:4441/grid/register -port5557 -browser
//
browserName=firefox -browser browserName=chrome
RemoteWebDriver driver= new RemoteWebDriver(new URL("http://localhost:4441/wd/hub"),cap);
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("meera");
driver.findElement(By.id("Passwd")).sendKeys("ana");
}
}