今天我嘗試了GhostDriver和Phantomjs。 當我使用GhostDriver時,它運行良好。 這樣開始無法通過Selenium Grid2使用RemoteWebDriver(Ghost,Phantom)
phantomjs --webdriver = 8910 然後
new RemoteWebDriver(new URL("http://localhost:8910"), sCaps);
我的硒測試用例可以通過。
然後我試圖使用Selenium2Grid, 所以啓動硒獨立服務器作爲一個樞紐:
D:\_Try\selenium>java -jar selenium-server-standalone-2.31.0.jar -role hub
2013-3-20 14:13:49 org.openqa.grid.selenium.GridLauncher main
信息: Launching a selenium grid server
2013-03-20 14:13:50.026:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2013-03-20 14:13:50.060:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2013-03-20 14:13:50.068:INFO:osjs.AbstractConnector:Started [email protected]:4444
然後註冊GhostDriver到轂
C:\Users\administrator>phantomjs --webdriver=8910 --webdriver-selenium-grid-hub=http://localhost:4444
PhantomJS is launching GhostDriver...
Ghost Driver running on port 8910
Registered with grid hub: http://localhost:4444/ (ok)
然後我經由網格檢查登記控制檯:http://localhost:4444/grid/console
,發現phantomjs已經註冊。 所以我修改了代碼,客戶端應該訪問網格:
new RemoteWebDriver(new URL("http://localhost:4444"), sCaps);
重新運行硒測試用例, 我認爲這將很好地工作,但例外拋出:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
at net.pipitest.selenium.trial.ghost.BaseTest.prepareDriver(BaseTest.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
我調試在代碼中, 發現在RemoteWebDriver.class中,響應是Selenium Grid Page(http://localhost:4444
) 的源代碼,它應該是這樣的MAP對象(下面是我直接使用GhostDriver時得到的): [platform =窗戶-7-32bi t,acceptSslCerts = false,javascriptEnabled = true,browserName = phantomjs,rotate = false,locationContextEnabled = false,version = phantomjs-1.8.1 + ghostdriver-1.0.2,databaseEnabled = false,cssSelectorsEnabled = true,handlesAlerts = false,browserConnectionEnabled = false,webStorageEnabled = false,proxy = {proxyType = direct},nativeEvents = true,applicationCacheEnabled = false,takesScreenshot = false]
有沒有人遇到過這個問題? 還是有什麼建議? 在此先感謝。
對這個問題有什麼好運? – 2014-01-02 13:10:24