I tried GhostDriver and Phantomjs today. When I use GhostDriver, it works well. start like this
phantomjs --webdriver=8910 then
new RemoteWebDriver(new URL("http://localhost:8910"), sCaps);
My selenium test case can pass.
Then I tried to use Selenium2Grid, so I start selenium standalone server as a hub:
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
then register GhostDriver to the hub
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)
then I checked the registration via the Grid console: http://localhost:4444/grid/console
and found phantomjs has already registered.
so I modified the code, the client should visit the grid:
new RemoteWebDriver(new URL("http://localhost:4444"), sCaps);
re-run the selenium test case, I thought it would work well, but exception throws:
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)
I debugged into the code,
found that in RemoteWebDriver.class, the response is the source code of Selenium Grid Page (http://localhost:4444
)
which should be a MAP Object like this(the below is what I get When using GhostDriver directly):
[platform=windows-7-32bit, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=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]
Does anyone meet this problem before? Or any suggestions? Thanks in advance.