This post guides us for the GRID implementation of Selenium where we launch a grid server and register two nodes in two different machines.
Here we launch the HUB in machine1 and start node 1 with two instances of chrome browser and node 2 with two instances of Firefox.
To start Hub
HUB: Machine 1
java -jar selenium-server-standalone-2.43.1.jar -role hub -port 4455
To start nodes
Node : Machine 2 (launching only chrome browser of 2 instances)
java -jar selenium-server-standalone-2.43.1.jar -role node -hub http://<ip_of_hub_machine:4455>/grid/register -port 5557 -Dwebdriver.chrome.driver=chromedriver.exe -browser browserName=chrome,platform=WINDOWS,maxInstances=2
Node: Machine 3 (launching only firefox browser of 2 instances)
java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://<ip_of_hub_machine:4455>/grid/register -port 5587 -browser browserName=firefox,platform=WINDOWS,maxInstances=2
After launching hub and nodes we can see the instances of the nodes in grid console under URL http://localhost:4455/grid/console
Sample program:
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class GridTest {
static DesiredCapabilities dc = null;
WebDriver driver;
public GridTest() throws MalformedURLException {
dc = new DesiredCapabilities();
}
public void firefox() throws MalformedURLException, InterruptedException {
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
excute("firefox");
}
public void chorme() throws MalformedURLException, InterruptedException {
dc.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
excute("chrome");
}
public void excute(String browsername) throws MalformedURLException, InterruptedException {
dc.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(
"http://<ip_of_hub_machine:4455>/wd/hub"), dc);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.out.println("In "+browsername);
driver.get("https://www.google.co.in/");
System.out.println(driver.getCurrentUrl());
driver.quit();
}
public static void main(String[] args) throws MalformedURLException, InterruptedException {
// TODO Auto-generated method stub
GridTest t1 = new GridTest();
t1.firefox();
t1.chorme();
}
}
Firefox in Machine 1 |
Chrome in Machine 2 |
No comments:
Post a Comment