Mac OS Sierra ( 10.12.5 ) When I start selenium server with hub role from command line as below
java -jar selenium-server-standalone-3.4.0.jar -role hub
After this opening grid console with url http://localhost:4444/grid/console, show info within couple of seconds.
But same url either doesn't load or take really long time to load, when I start hub with java programme as below
Hub hub = null;
public void startSeleniumHub(){
try{
String strIP = "localhost";
GridHubConfiguration config = new GridHubConfiguration();
config.host = strIP;
config.port = 4444;
hub = new Hub(config);
hub.start();
if(isSeleniumHubRunning(10)){
System.out.println("Selenium Grid is Running");
}else{
System.err.println("*** Selenium Grid is down");
}
}catch(Exception e){
e.printStackTrace();
}
}
public boolean isSeleniumHubRunning(int timeOut){
int count = 0 ;
while(count < timeOut){
try{
Thread.sleep(1000);
URL u = new URL ( "http://localhost:4444/grid/console");
HttpURLConnection huc = ( HttpURLConnection ) u.openConnection ();
huc.setRequestMethod ("GET"); //OR huc.setRequestMethod ("HEAD");
huc.connect () ;
int code = huc.getResponseCode() ;
System.out.println(code);
return true;
}catch(Exception e){
System.err.println("Selenium Grid is still down.....");
count++;
//return false;
}
}
System.err.println("Selenium Grid failed to start up even after " + timeOut + " seconds");
return false;
}
I tried searching for root cause but didn't find any answer.
Thanks in advance.
EDIT: Below solution from krishnan-mahadevan ONLY works with Eclipse 4.6.0 and NOT with IDEA Community Edition 2017.2 I'm going to open new question for IDEA regarding this.