2012-01-19 31 views
0

我使用本網站的代碼(http://darrellgrainger.blogspot.com/2011/02/using-selenium-20-with-webdriver-and.html)運行Selenium在Safari 5.代碼測試是這樣的:使用Selenium測試Safari給出GridException

Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL); 
CommandExecutor executor = new SeleneseCommandExecutor(sel); 
DesiredCapabilities dc = new DesiredCapabilities(); 
WebDriver browser = new RemoteWebDriver(executor, dc); 

browser.get("http://www.google.com"); 
WebElement input = browser.findElement(By.name("q")); 
input.sendKeys("Selenium"); 

所以我啓動本地主機機器上的硒服務器獨立版本和我寄存器測試節點(還本地主機)到硒轂。然後我開始測試。然後我得到以下異常:org.openqa.selenium.WebDriverException:無法啓動Selenium會話:org%2Eopenqa%2Egrid%2Ecommon%2Eexception%2EGridException%3A +錯誤+轉發+ +新+會話+ +服務器+返回+ an + error +%3A +

我不知道什麼錯誤。控制檯上沒有服務器輸出。有沒有人有想法?我使用了Selenium的最新版本(2.17.0)。

編輯:我只是嘗試「火狐」而不是safari,它輸出相同的異常。所以實際上這不是Safari的錯。也許通過網格執行Selenium 1代碼有問題嗎?

回答

0

試試這個:

DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setBrowserName("safari"); 
capabilities.setJavascriptEnabled(true); 
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:5555/"), new URL("http://www.google.com/"), capabilities); 
WebDriver driver = new RemoteWebDriver(executor, capabilities); 
driver.get("http://google.com"); 

不要創建DefaultSelenium對象。以上代碼適用於Safari瀏覽器。

+0

這給了我以下異常:org.openqa.selenium.WebDriverException:無法啓動Selenium會話:org%2Eopenqa%2Egrid%2Ecommon%2Eexception%2EGridException%3A + Error + forwarding + the + new + session + can not +找到+%3A +%7BbrowserName%3D%2Asafari%7D 如何將測試機器註冊到集線器?我使用了「瀏覽器browserName = safari」 – tester

+0

當您創建網格節點時,不要提供瀏覽器名稱。 –