如果問題是關於在GRID2使用Safari的新方式,用SafariDriver,那麼這將是典型的方法,我相信(或多或少):
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import java.net.*;
DesiredCapabilities c = new DesiredCapabilities();
c.setBrowserName("safari");
/* you can then set version & platform as well, but the minimum is just browser. Maybe for Grid2 you need the others, but for remote web driver only, you don't.
*/
WebDriver d = new RemoteWebDriver(new URL("http://hubIpOrHostname:hubPort/wd/hub"),c);
,並應工作。在服務器端,我相信你只是爲每個維基文檔的Grid2實例化(最後我檢查,現在可能不一樣):
//啓動集線器 java -jar selenium-server-standalone-2.21.0。罐子-role轂-port theHubPort
//啓動節點 Java的罐子硒 - 服務器 - 獨立-2.21.0.jar -role節點-hub HTTP: //172.22.6.198:4446/wd/hub但是,似乎目前的Grid2並不提供Safari支持。當我查找集線器中註冊節點的控制檯時,它沒有顯示Safari的圖標。也許我錯過了什麼。下次我會嘗試添加平臺和版本,看看是否有差異,但不要想。
下面是錯誤的一個片段,我得到了GRID2與SafariDriver:
2012年5月11日下午6時01分11秒org.openqa.selenium.remote.RemoteWebDriver執行 INFO:執行:[空,newsession的{「desiredCapabilities」:「Capabilities [{}} {}}}}}}} //錯誤://未捕獲的異常:類型變量聲明:對象構造函數 :at行:7:in file :: new RemoteWebDriver URL(「http: //172.22.6.198:4446/wd/hub」),c)
目標異常:org.openqa.selenium.WebDriverExcept離子:錯誤轉發所述n EW會話不能找到:{browserName =狩獵} 命令持續時間或超時:109毫秒
需要注意的:與webdriver的,相同的代碼可以被用於(獨立)遠程的webdriver執行VS網格,區別在於,對於使用遠程服務器ip和grid2的遠程,您使用hub ip。 SafariDriver通過遠程webdriver工作,但目前似乎還沒有在Grid2上工作。
遠程啓動的webdriver:
Java的罐子selenum服務器 - 獨立-2.21.0。jar [-port somePort] //默認端口4444
您使用的是哪個版本的Selenium?根據[用戶Darrell的最新評論],Safari瀏覽器無法正常工作(http://darrellgrainger.blogspot.co.uk/2011/02/using-selenium-20-with-webdriver-and.html?showComment = 1333108018252#c9157838719535505020) – shamp00 2012-04-25 13:14:54