Selenium:http:// localhost:4444 / wd / hub返回NullPointerException,我做错了什么

时间:2017-01-16 18:31:54

标签: java c# selenium selenium-webdriver

鉴于:尝试使用此代码在C#中使用RemoteWebDriver。

var url = new Uri("http://localhost:4444/wd/hub");
var wd = new RemoteWebDriver(url, DesiredCapabilities.Chrome());

上面的新RemoteWebDriver代码在超时后才会响应......

更多详情

我已经使用这些参数启动了我的Hub到Selenium Server:

-jar "C:\SomeFolder\selenium-server-standalone-3.0.1.jar" -port 4444 -role hub

使用这些参数注册了一个节点..

-jar "C:\SomeFolder\selenium-server-standalone-3.0.1.jar" -role node -hub http://localhost:4444/grid/register -port 9662 

调试

如果我在启动集线器后输入此URL,则表明存在已注册的节点:

http://location:4444/grid/console

但是在启动Hub后输入此URL

http://localhost:4444/wd/hub

浏览器显示指向ExternalSessionKey.java的这个java(json)堆栈跟踪

{"status":13,"value":{"class":"java.lang.NullPointerException","stackTrace":[{"fileName":"ExternalSessionKey.java","className":"org.openqa.grid.internal.ExternalSessionKey","methodName":"fromWebDriverRequest","lineNumber":77},{"fileName":"WebDriverRequest.java","className":"org.openqa.grid.web.servlet.handler.WebDriverRequest","methodName":"extractSession","lineNumber":62},{"fileName":"RequestHandler.java","className":"org.openqa.grid.web.servlet.handler.RequestHandler","methodName":"getSession","lineNumber":231},{"fileName":"RequestHandler.java","className":"org.openqa.grid.web.servlet.handler.RequestHandler","methodName":"process","lineNumber":118},{"fileName":"DriverServlet.java","className":"org.openqa.grid.web.servlet.DriverServlet","methodName":"process","lineNumber":83},{"fileName":"DriverServlet.java","className":"org.openqa.grid.web.servlet.DriverServlet","methodName":"doGet","lineNumber":61},{"fileName":"HttpServlet.java","className":"javax.servlet.http.HttpServlet","methodName":"service","lineNumber":687},{"fileName":"HttpServlet.java","className":"javax.servlet.http.HttpServlet","methodName":"service","lineNumber":790},{"fileName":"ServletHolder.java","className":"org.seleniumhq.jetty9.servlet.ServletHolder","methodName":"handle","lineNumber":808},{"fileName":"ServletHandler.java","className":"org.seleniumhq.jetty9.servlet.ServletHandler","methodName":"doHandle","lineNumber":587},{"fileName":"SessionHandler.java","className":"org.seleniumhq.jetty9.server.session.SessionHandler","methodName":"doHandle","lineNumber":221},{"fileName":"ContextHandler.java","className":"org.seleniumhq.jetty9.server.handler.ContextHandler","methodName":"doHandle","lineNumber":1127},{"fileName":"ServletHandler.java","className":"org.seleniumhq.jetty9.servlet.ServletHandler","methodName":"doScope","lineNumber":515},{"fileName":"SessionHandler.java","className":"org.seleniumhq.jetty9.server.session.SessionHandler","methodName":"doScope","lineNumber":185},{"fileName":"ContextHandler.java","className":"org.seleniumhq.jetty9.server.handler.ContextHandler","methodName":"doScope","lineNumber":1061},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"handle","lineNumber":141},{"fileName":"HandlerWrapper.java","className":"org.seleniumhq.jetty9.server.handler.HandlerWrapper","methodName":"handle","lineNumber":97},{"fileName":"Server.java","className":"org.seleniumhq.jetty9.server.Server","methodName":"handle","lineNumber":499},{"fileName":"HttpChannel.java","className":"org.seleniumhq.jetty9.server.HttpChannel","methodName":"handle","lineNumber":310},{"fileName":"HttpConnection.java","className":"org.seleniumhq.jetty9.server.HttpConnection","methodName":"onFillable","lineNumber":257},{"fileName":"AbstractConnection.java","className":"org.seleniumhq.jetty9.io.AbstractConnection$2","methodName":"run","lineNumber":540},{"fileName":"QueuedThreadPool.java","className":"org.seleniumhq.jetty9.util.thread.QueuedThreadPool","methodName":"runJob","lineNumber":635},{"fileName":"QueuedThreadPool.java","className":"org.seleniumhq.jetty9.util.thread.QueuedThreadPool$3","methodName":"run","lineNumber":555},{"className":"java.lang.Thread","methodName":"run","lineNumber":-1}]}}

任何人都可以为我解释堆栈跟踪,以及如何使其工作?

谢谢!

2 个答案:

答案 0 :(得分:8)

你的结局没有错。

网址http://localhost:4444/wd/hub的设计使其需要PAYLOAD与您的操作。由于您还没有提供所需的有效负载,因此您会看到NullPointerException。

此URL不应在浏览器中打开。它意味着通过Http操作使用适当的有效负载来遵守Selenium w3c spec

答案 1 :(得分:1)

问题的症状是此代码中的连接超时异常。

var url = new Uri("http://localhost:4444/wd/hub");
var wd = new RemoteWebDriver(url, DesiredCapabilities.Chrome());

根本原因

这是因为,在我的调试会话期间;我在本声明之前结束了该计划:

wd.Quit();

由于我的Hub仅配置了一个节点,因此先前的调试会话仍然在集线器上有一个孤立的会话。重新启动集线器修复了这个问题,但是也可以根据需要配置多个节点。

Hub逻辑的另一个错误是孤立节点未在配置中设置的正确超时中清除。这会导致孤立节点保持活动的时间远远超过超时建议...查看配置选项以便自己查看。应该有一个不活动计时器,上面写着“如果x秒内没有活动”会终止会话。

一个解决方案

确保(至少)配置集线器,以便在调试解决方案时允许更多节点。