2017-07-24 32 views
0

的Mac OS塞拉利昂(10.12.5) 當我從命令行啓動硒服務器樞紐的角色如下硒網格控制檯不打開硒樞紐編程方式啓動

java -jar selenium-server-standalone-3.4.0.jar -role hub 

這種開放網格控制檯後網址http://localhost:4444/grid/console,幾秒鐘內顯示信息。

但相同的URL或者不加載或需要很長的時間來加載,當我開始樞紐,java程序如下

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; 
     } 

我試圖尋找根源,但沒有找到任何答案。

在此先感謝。

編輯:下面由克里希南,馬哈德與Eclipse 4.6.0只適用的解決方案和不IDEA社區版2017.2我要打開IDEA對此新問題。

+0

您能告訴我們您的完整實施嗎?謝謝 – DebanjanB

+0

@DebanjanB我編輯了這個問題,並添加了2個啓動和檢查集線器工作正常運行的方法。 – vikramvi

+0

Hub爲你啓動多少時間?你的代碼在我的電腦上@ 1412ms,而通過'java -jar'的默認時間有時是2757ms。我猜你的代碼是非常好的。 – DebanjanB

回答

0

我將整合迄今爲止共享的所有內容,其中this Google forum thread的部分內容也與OP有相同的討論。

  1. 在Sierra OS上,有一個已知問題,有時需要很長時間才能解析本地主機的IP地址。爲了解決這個問題,您需要將hostname命令的輸出添加到/etc/hosts文件中,然後嘗試。有關更多詳情,請參閱this SO帖子。
  2. 如果你是一個企業網絡上有你和互聯網之間的代理服務器坐着,那麼你可能必須嘗試通過是爲任何localhostIP Address of your machineNetwork Preferences > Advanced (Click "Advanced" button) > Proxies (tab) > Bypass proxy settings for these hosts & domains
  3. 通流量配置代理服務器設置

一旦你完成了上述兩種的,你可以嘗試以下提到的組合之一用於啓動和加載了網格控制檯:

  1. 明確提供主機名稱爲localhost(你的代碼是已經在做)然後加載你通過http://localhost:4444/grid/console(或)
  2. 通過跳過主機名的設置並加載由hub.getUrl()返回的URL來重複步驟(1)。

我的預感是,你可能在公司提供的MAC,並且它配置了代理服務器。因此,當您打開瀏覽器並嘗試加載控制檯URL時,流量首先會被路由到嘗試解析頁面的代理服務器,並在花費很長時間後最終失敗,因爲您的代理既不知道您的localhost也不知道您的IP address機器(我猜你最終會使用內部IP地址,這可能不會暴露在外面)

希望有所幫助!