ClassNotFoundException org.openqa.selenium.WebDriver

时间:2014-08-07 18:10:36

标签: java maven junit jboss jboss-arquillian

当我运行Arquillian测试时,我收到错误:

  

java.lang.NoClassDefFoundError:Lorg / openqa / selenium / WebDriver;在   java.lang.Class.getDeclaredFields0(Native Method)at   java.lang.Class.privateGetDeclaredFields(Class.java:2570)at at   java.lang.Class.getDeclaredFields(Class.java:1903)at   org.junit.runners.model.TestClass.getSortedDeclaredFields(TestClass.java:77)     在   org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:70)     在org.junit.runners.model.TestClass。(TestClass.java:57)at   org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)     在org.junit.runners.ParentRunner。(ParentRunner.java:83)at   org.junit.runners.BlockJUnit4ClassRunner。(BlockJUnit4ClassRunner.java:63)     在org.jboss.arquillian.junit.Arquillian。(Arquillian.java:55)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native   方法)at   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:408)     在   org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)     在   org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)     在   org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)     在   org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)     在   org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)     在   org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)     在   org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)     在org.junit.runner.JUnitCore.run(JUnitCore.java:115)at   org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:66)     在   org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:159)     在   org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:125)     在   org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:89)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:687)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at at   io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)     在   io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)     在   io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)     在   org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)     在   io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)     在   io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)     在   io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)     在   io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)     在   io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)     在   io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)     在   io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)     在   io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)     在   io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)     在   org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)     在   io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)     在   io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)     在   io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)     在   io.undertow.servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:73)     在   io.undertow.servlet.handlers.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:146)     在   io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)     在   io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:727)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)引起:   java.lang.ClassNotFoundException:org.openqa.selenium.WebDriver from   [Module" deployment.sp.war:main"来自服务模块加载器]   org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)     在   org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)     在   org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)     在   org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)     在   org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)     ......还有56个

我的pom.xml:

<!--Tests-->
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${version.junit}</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.jboss.arquillian.junit</groupId>
  <artifactId>arquillian-junit-container</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.jboss.arquillian.extension</groupId>
  <artifactId>arquillian-drone-webdriver-depchain</artifactId>
  <type>pom</type>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>xerces</groupId>
  <artifactId>xercesImpl</artifactId>
  <version>2.11.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.wildfly</groupId>
  <artifactId>wildfly-arquillian-container-embedded</artifactId>
  <version>8.1.0.Final</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.jboss.arquillian.extension</groupId>
  <artifactId>arquillian-angularjs-graphene</artifactId>
  <version>1.2.0.Alpha1</version>
  <type>pom</type>
</dependency>
<dependency>
  <groupId>org.jboss.shrinkwrap.resolver</groupId>
  <artifactId>shrinkwrap-resolver-depchain</artifactId>
  <version>${version.shrinkwrap.resolvers}</version>
  <scope>test</scope>
  <type>pom</type>
</dependency>

我打包测试网站存档如下:

public class Deployments {
  public static Archive createDeployment() {
    return ShrinkWrap.create(MavenImporter.class)
        .loadPomFromFile("/Users/alekspo/Documents/Development/Java/WildFly/sp/pom.xml")
        .importBuildOutput().as(WebArchive.class);
  }
}

我知道为什么会出现这样的NoClassDefFound错误?

2 个答案:

答案 0 :(得分:2)

我今天遇到了完全相同的问题。这肯定不是一个依赖性问题。堆栈跟踪已经暗示Arquillian正在尝试在服务器本身运行Drone测试,而不是充当客户端。这是第一个奇怪的,因为我们实际上想要将其作为客户端运行。如何做到这一点在Arquillian的指南Functional Testing using Drone and Graphene中描述:

  

启用客户端模式

     

如何激活客户端模式?很简单。您可以将部署标记为不可测试,这意味着Arquillian不会丰富存档,或者您可以使用注释@RunAsClient标记指定的方法。

换句话说,你需要

@RunWith(Arquillian.class)
public class Test {

    @Deployment(testable = false)
    public static Archive<?> createDeployment() {
        // ...
    }

    @Test
    public void test() {
        // ...
    }

}

@RunWith(Arquillian.class)
public class Test {

    @Deployment
    public static Archive<?> createDeployment() {
        // ...
    }

    @Test
    @RunAsClient
    public void test() {
        // ...
    }

}

这至少解决了我的问题。

答案 1 :(得分:0)

您需要为selenium添加maven依赖项。

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.42.2</version>
    <scope>test</scope>
</dependency>