Spring Boot JUnit with Selenium ClassNotFoundException: org.apache.xml.utils.PrefixResolver

前端 未结 1 1291
心在旅途
心在旅途 2020-12-04 03:48

I am trying to run a simple test with selenium, but I am getting ClassNotFoundException when I run my test and I don\'t know what dependency to import to solve this issue.

1条回答
  •  暖寄归人
    2020-12-04 04:21

    java.lang.ClassNotFoundException

    ClassNotFoundException in Java is a subclass of java.lang.Exception and occurs when Java Virtual Machine tries to load a particular class and doesn't finds the requested class in classpath. It is a checked Exception and explicit Exception handling methods are required to what can possibly be throwing ClassNotFoundException either by using try-catch block or by using throws clause.

    As per the Java Docs ClassNotFoundException comes in following cases:

    1. When we try to load a class by using Class.forName() method and .class file or binary of class is not available in classpath.
    2. When Classloader try to load a class by using findSystemClass() method.
    3. While using loadClass() method of class ClassLoader in Java.

    ClassNotFoundExcepiton can arise only when JVM tries to load a class at run-time but nothing related to compile time which is unlike NoClassDefFoundError. This is because till run time JVM doesn't know about this Class and it can only be done by above specified method or by employing Reflection to read the name of class from some configuration and then load the class specified on those configuration file.


    This usecase

    The error does gives us a hint what is going wrong as follows :

    Caused by: java.lang.ClassNotFoundException: org.apache.xml.utils.PrefixResolver
    

    As per the pom.xml you have shared clearly the x.y.z tag is missing. You need to change the as follows :

    • selenium-api

      
      
          org.seleniumhq.selenium
          selenium-api
          3.10.0
      
      
    • selenium-htmlunit-driver

       
       
           org.seleniumhq.selenium
           selenium-htmlunit-driver
           2.52.0
       
      

    As you are using spring-boot 1.5.10 additionally you may also require to add either of the following :

    • selenium-java

      
      
          org.seleniumhq.selenium
          selenium-java
          3.10.0
      
      
    • selenium-server

      
      
          org.seleniumhq.selenium
          selenium-server
          3.10.0
      
      

    0 讨论(0)
提交回复
热议问题