简体   繁体   English

春季测试HTMLUnit NoSuchMethod CookieManager.getCookies(URL)

[英]Spring Test HTMLUnit NoSuchMethod CookieManager.getCookies(URL)

I'm having an problem running HTMLUnit tests using spring-test-htmlunit. 我在使用spring-test-htmlunit运行HTMLUnit测试时遇到问题。 When calling getPage() on an instance of WebClient, I get a noSuchMethod error as follows: 在WebClient实例上调用getPage()时,出现如下的noSuchMethod错误:

java.lang.NoSuchMethodError: com.gargoylesoftware.htmlunit.CookieManager.getCookies(Ljava/net/URL;)Ljava/util/Set;
    at org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilder.cookies(HtmlUnitRequestBuilder.java:267)
    at org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilder.buildRequest(HtmlUnitRequestBuilder.java:104)
    at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
    at org.springframework.test.web.servlet.htmlunit.MockMvcWebConnection.getResponse(MockMvcWebConnection.java:111)
    at org.springframework.test.web.servlet.htmlunit.MockMvcWebConnection.getResponse(MockMvcWebConnection.java:96)
    at org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.getResponse(DelegatingWebConnection.java:68)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1357)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1274)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:451)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:436)

I've tried excluding the HTMLUnit version from spring-test-htmlunit and adding the latest version. 我试过从spring-test-htmlunit中排除HTMLUnit版本,并添加最新版本。 I also have a dependency for nekoHTML that is needed for thymeleaf template compilation. 我也有一个对nekoHTML的依赖,这是百里香模板编译所需要的。

relevant pom.xml 相关的pom.xml

 <dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
    <version>1.9.21</version>
 </dependency>
 <dependency>
    <groupId>org.springframework.test.htmlunit</groupId>
    <artifactId>spring-test-htmlunit</artifactId>
    <version>1.0.0.RC1</version>
    <scope>test</scope>
 </dependency>
 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

the offending call 冒犯性的电话

HtmlPage page = webClient.getPage("http://localhost:8080/");

Usually, this is a dependency conflict, you can print down the currently used JARs by something like: 通常,这是一个依赖冲突,您可以通过以下方式打印当前使用的JAR:

System.out.println(WebClient.class.getProtectionDomain().getCodeSource().getLocation());
System.out.println(HTMLElements.class.getProtectionDomain().getCodeSource().getLocation());

And ensure the Neko version is compatible with the corresponding HtmlUnit version. 并确保Neko版本与相应的HtmlUnit版本兼容。

Also, spring boot includes specific HtmlUnit version, which may not be what you want. 另外,Spring Boot包含特定的HtmlUnit版本,这可能不是您想要的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM