Selenium 独立服务器的实例,节点返回 com.google.gson.JsonPrimitive.isPrimitiveOrString 引发的 500 错误响应 NullPointerException
任何解决此错误的提示都非常感谢。
启动 Selenium 服务器集线器和节点 检查节点是否列在服务器控制台上。
软件版本:
- 阿帕奇 Maven 3.5.0
- selenium-server-standalone-3.5.0
- ChromeDriver 2.31 - geckodriver-v0.18.0-win64
- Chrome v 60.0.3112.101(64 位)
- 火狐 55.0.2(64 位)
- Java 1.8.0_92(64 位)
服务器启动命令:
java -jar "selenium-server-standalone-3.5.0.jar" -role hub
java -Dwebdriver.gecko.driver="C:/selenium/geckodriver.exe" -jar "selenium-server-standalone-3.5.0.jar" -role node -hub http://localhost:4444/grid/register
Maven POM:
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
Java 类(不包括导入):
public class GoogleSearchTest extends TestCase {
public void testApp() throws MalformedURLException {
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
driver.navigate().to("http://www.google.com/");
} }
错误堆栈:
Problem accessing /wd/hub/session. Reason:
Caused by: java.lang.NullPointerException ** at com.google.gson.JsonPrimitive.isPrimitiveOrString(JsonPrimitive.java:278)
at com.google.gson.JsonPrimitive.setValue(JsonPrimitive.java:101)
at com.google.gson.JsonPrimitive.<init>(JsonPrimitive.java:65)
at org.openqa.selenium.remote.server.ExceptionHandler.lambda$execute$0(ExceptionHandler.java:82)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.collect(Unknown Source)
这个错误似乎在自动化测试的早期就出现了。我还没有答案的问题:发送的 JSON 有效负载是什么,是否需要配置其他功能。
类似帖子