我正在使用 htmlunit-2/.9 版本,当我尝试获取当前的 HTML 页面内容并将其保存到临时文件以供将来参考时,当我调用currentPage.asXml()
.
任何指针或帮助将不胜感激。
这是堆栈跟踪:
java.lang.NullPointerException
at **com.gargoylesoftware.htmlunit.SgmlPage.asXml(SgmlPage.java:206)**
at com.yahoo.vis.ddbuilder.validator.DDBuilderValidator.validateTemplate_1(DDBuilderValidator.java:308)
at com.yahoo.vis.ddbuilder.validator.DDBuilderValidator.validate(DDBuilderValidator.java:72)
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.yahoo.robot.components.interfaces.Executable.run(Executable.java:73)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
下面是导致 NULL 指针的代码片段。我正在为大约 100 个测试用例运行此测试,在 100 个测试用例中,20-30 个用例会随机失败
private IValidationResponse validateTemplate_2(String url, Properties verifyProps, HtmlPage currentPage) throws FailingHttpStatusCodeException, MalformedURLException, IOException
{
IValidationResponse validationResponse = new DefaultValidationResponse();
String query = verifyProps.getProperty(IConstants.QUERY);
System.err.println("Verifying Query ::- "+query);
validationResponse.setQuery(query);
validationResponse.setActualResponseAsBuffer(new StringBuffer(currentPage.asXml()));
...
}