带有Selenium的Spring Boot JUnit ClassNotFoundException:org.apache.xml.utils.PrefixResolver

时间:2018-03-07 13:55:31

标签: java selenium spring-boot junit

我正在尝试使用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>

1 个答案:

答案 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>