【问题标题】:Selenium grid console doesn't open for Selenium Hub started programmaticallySelenium 网格控制台未打开以编程方式启动的 Selenium Hub
【发布时间】: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 根本没有打开。
  • 您的意思是您无法通过任何浏览器手动访问网址?

标签: selenium selenium-grid


【解决方案1】:

我将整合我迄今为止分享的所有内容,作为 this Google forum thread 的一部分,该部分也与 OP 进行了相同的讨论。

  1. 在 Sierra OS 上,有一个已知问题,有时需要很长时间才能解析 localhost 的 IP 地址。为了解决这个问题,您需要将hostname 命令的输出添加到/etc/hosts 文件中,然后尝试。有关详细信息,请参阅this SO 帖子。
  2. 如果您在企业网络上并且在您和 Internet 之间有一个代理服务器,那么您可能必须尝试配置代理设置以绕过用于 localhostIP Address of your machine 的流量来自Network Preferences &gt; Advanced (Click "Advanced" button) &gt; Proxies (tab) &gt; Bypass proxy settings for these hosts &amp; domains

完成上述两项后,您可以尝试以下组合之一来启动和加载 Grid 控制台:

  1. 将主机名明确提供为localhost(您的代码已经这样做了),然后通过http://localhost:4444/grid/console(或)加载网格控制台
  2. 通过跳过主机名设置并加载hub.getUrl()返回的URL,重复步骤(1)。

我的直觉是,您可能在公司提供的 MAC 上,并且它配置了代理服务器。因此,当您打开浏览器并尝试加载控制台 URL 时,流量首先被路由到尝试解析页面的代理服务器,并在花费很长时间后最终失败,因为您的代理既不知道 localhost 也不知道 @你机器的 987654332@ (我猜你最终使用了一个可能没有暴露在外面的内部 IP 地址)

希望有帮助!

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多