我正在尝试使用selenium运行一个简单的测试,但是当我运行测试时我得到ClassNotFoundException并且我不知道要导入哪个依赖项来解决这个问题。
我找不到任何与此不同的例子。
我正在使用Java 8和spring-boot 1.5.10.RELEASE
你能帮帮我吗?
MKtileOverlay
的pom.xml
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class VersaoControllerTest extends AbstractTest{
@Autowired
private MockMvc mockMvc;
@Autowired
private WebDriver webDriver;
@Test
public void test() {
this.webDriver.get("/");
}
}
错误:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<scope>test</scope>
</dependency>
答案 0 :(得分:1)
错误确实给了我们一个如下错误的提示:
Caused by: java.lang.ClassNotFoundException: org.apache.xml.utils.PrefixResolver
根据 pom.xml ,您已清楚地分享了 <version>x.y.z</version>
标记。您需要更改 ,如下所示:
<强> selenium-api
强>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.10.0</version>
</dependency>
<强> selenium-htmlunit-driver
强>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>
当您使用 spring-boot 1.5.10 时,您可能还需要添加以下任一 <dependency>
:
<强> selenium-java
强>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.10.0</version>
</dependency>
<强> selenium-server
强>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.10.0</version>
</dependency>