【发布时间】:2017-07-24 11:39:10
【问题描述】:
Mac OS Sierra (10.12.5) 当我从命令行启动具有集线器角色的 selenium 服务器时,如下所示
java -jar selenium-server-standalone-3.4.0.jar -role hub
在打开带有 url http://localhost:4444/grid/console 的网格控制台后,几秒钟内显示信息。
但是当我使用下面的 java 程序启动集线器时,相同的 url 要么不加载,要么需要很长时间才能加载
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;
}
我尝试搜索根本原因,但没有找到任何答案。
提前致谢。
编辑:krishnan-mahadevan 的以下解决方案仅适用于 Eclipse 4.6.0 和 不适用于 IDEA Community Edition 2017.2 我将为 IDEA 提出新问题这个。
【问题讨论】:
-
你能告诉我们你的完整实现吗?谢谢
-
@DebanjanB 我已经编辑了问题并添加了 2 个方法来完成启动和检查集线器是否启动和运行的工作。
-
Hub 需要多长时间才能启动?您的代码在我的 PC 上占用 @1412ms,而通过
java -jar的默认时间有时会占用 @2757ms。我猜你的代码是相当优化的。 -
@DebanjanB 查询是关于网格控制台 url 根本没有打开。
-
您的意思是您无法通过任何浏览器手动访问网址?