当我从命令行使用hub角色启动selenium服务器时,MacOS塞拉利昂( 10.12.5 )如下所示
java -jar selenium-server-standalone-3.4.0.jar -role hub在使用url http://localhost:4444/grid/console打开网格控制台之后,在几秒钟内显示信息。
但是当我使用java程序启动hub时,相同的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的解决方案,只使用Eclipse4.6.0和,而不是IDEA Community 2017.2,我将对IDEA提出新的问题。
发布于 2017-07-25 02:45:43
我将整合我共享的所有内容,作为这个Google论坛的帖子的一部分,它也与OP进行了相同的讨论。
hostname命令的输出添加到/etc/hosts文件中,然后尝试。有关更多细节,请参见这。localhost或来自Network Preferences > Advanced (Click "Advanced" button) > Proxies (tab) > Bypass proxy settings for these hosts & domains的IP Address of your machine的。完成以上两项操作之后,您可以尝试下面提到的一个组合来引导和加载Grid控制台:
localhost (您的代码已经在这样做),然后通过http://localhost:4444/grid/console (或)加载网格控制台。hub.getUrl()返回的方式加载URL。我的直觉是,您可能是在一家公司提供的MAC和它有一个代理服务器配置。因此,当您打开浏览器并尝试加载控制台URL时,流量首先被路由到代理服务器,该代理服务器试图解析页面,并在花了很长时间后最终失败,因为您的代理既不知道localhost,也不知道机器的IP address (我猜您最终使用的是内部IP地址,而这个IP地址可能不会暴露在外部)。
希望这能帮上忙!
https://stackoverflow.com/questions/45279669
复制相似问题