问题
I'm trying to launch remoteWebdriver, for that I have created a hub progmatically then I have added a node on it. That is fine.The problem now when I execute:
Thread.currentThread().join();
The program stop executing, and if I remove this line I get error.
try{
String strIP = "localhost";
GridHubConfiguration config = new GridHubConfiguration();
config.setTimeout(30000000);
config.setPort(4444);
config.setHost(strIP);
Hub hub = new Hub(config);
hub.start();
RegistrationRequest req = new RegistrationRequest();
req.setRole(GridRole.NODE);
Map<String, Object> nodeConfiguration = new HashMap<>();
nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, DefaultRemoteProxy.class.getName());
nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 5);
nodeConfiguration.put(RegistrationRequest.PORT, 5555);
nodeConfiguration.put(RegistrationRequest.HOST, 4444);
nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true);
nodeConfiguration.put(RegistrationRequest.REGISTER_CYCLE, 5000);
nodeConfiguration.put(RegistrationRequest.HUB_HOST, "localhost");
nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444);
nodeConfiguration.put("remoteHost", "http://" + strIP + ":5555");
nodeConfiguration.put("url", "http://" + strIP + ":5555");
nodeConfiguration.put("role", "node");
nodeConfiguration.put("hub", "http://localhost:4444/grid/register");
URL remoteURL = new URL("http://" + strIP + ":5555");
nodeConfiguration.put(RegistrationRequest.REMOTE_HOST, remoteURL.toExternalForm());
req.setConfiguration(nodeConfiguration);
DesiredCapabilities capabilities2 = DesiredCapabilities.chrome();
capabilities2.setCapability("browserName", "chrome");
capabilities2.setCapability("platform", "WINDOWS");
capabilities2.setCapability("ensureCleanSession", "true");
capabilities2.setCapability("maxInstances", 5);
req.addDesiredCapability(capabilities2);
SelfRegisteringRemote remote = new SelfRegisteringRemote(req);
remote.setRemoteServer(new SeleniumServer(req.getConfiguration()));
remote.startRemoteServer();
remote.startRegistrationProcess();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/register"),DesiredCapabilities.chrome());
Thread.currentThread().join();
String URL="http://localhost:4444/wd/hub";
WebDriver driver = new RemoteWebDriver(new URL(URL),DesiredCapabilities.chrome());
driver.get("https://www.youtube.com");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/37006829/how-start-remote-webdriver-after-regitering-a-node-in-a-hub