2017-01-06 309 views
0

我试图通过Maven运行我的测试,但是我在构建过程中出现错误。我已经尝试了过去两天来解决这个问题,但现在已经没有想法。我已经确定我的POM具有正确的依赖关系,并且测试在Jenkins之外工作。Maven测试,詹金斯测试套件失败java.lang.NoClassDefFoundError -

OS - Windows Server 2012中R2 浏览器 - 火狐50.1.0 硒驱动程序 - 3.0.1

詹金斯错误日志

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 

Running TestSuite 
[App[email protected]] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified 

09:48:46.025 [main] INFO - START com.Ceridian.tests.HB01.CD01 
09:48:46.119 [main] WARN - SKIP com.Ceridian.tests.HB01.CD01 
09:48:46.119 [main] ERROR - Unable to take screenshot - java.lang.NullPointerException 
09:48:46.135 [main] INFO - START com.Ceridian.tests.HB01.CD02 
09:48:46.150 [main] WARN - SKIP com.Ceridian.tests.HB01.CD02 
09:48:46.150 [main] ERROR - Unable to take screenshot - java.lang.NullPointerException 
Tests run: 4, Failures: 2, Errors: 0, Skipped: 2, Time elapsed: 2.688 sec <<< FAILURE! - in TestSuite 
configureBrowserBeforeTest(com.Ceridian.tests.HB01) Time elapsed: 2 sec <<< FAILURE! 
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException 
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException 

configureBrowserBeforeTest(com.Ceridian.tests.HB01) Time elapsed: 0.093 sec <<< FAILURE! 
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException 
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException 

Results : 

Failed tests: 
com.Ceridian.tests.HB01.configureBrowserBeforeTest(com.Ceridian.tests.HB01) 
    Run 1: HB01>BaseTest.configureBrowserBeforeTest:102 » NoClassDefFound org/openqa/sele... 
    Run 2: HB01>BaseTest.configureBrowserBeforeTest:102 » NoClassDefFound org/openqa/sele... 

詹金斯失败构建

[JENKINS] Recording test results 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 37.354 s 
[INFO] Finished at: 2017-01-06T09:48:52+00:00 
[INFO] Final Memory: 34M/442M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project Frameworkium: There are test failures. 
[ERROR] 
[ERROR] Please refer to C:\Program Files (x86)\Jenkins\jobs\FirstAttempt\workspace\target\surefire-reports for the individual test results. 
[ERROR] -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project Frameworkium: There are test failures. 

POM文件

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.frameworkium</groupId> 
    <artifactId>Frameworkium</artifactId> 
    <packaging>jar</packaging> 
    <version>2.0.5</version> 

    <name>Frameworkium</name> 
    <description> 
     A template designed to get up and running quickly with Selenium and Appium. 
    </description> 
    <url/> 
    <inceptionYear/> 
    <organization/> 
    <licenses/> 

    <developers/> 
    <contributors/> 

    <prerequisites> 
     <maven>3.1.1</maven> 
    </prerequisites> 

    <modules/> 

    <scm/> 
    <issueManagement/> 
    <ciManagement/> 
    <distributionManagement/> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <env.config>local</env.config> 
     <threads>1</threads> 
     <groups/> 
     <aspectj.version>1.8.9</aspectj.version> 
    </properties> 

    <repositories> 
     <repository> 
      <id>jitpack.io</id> 
      <url>https://jitpack.io</url> 
     </repository> 
    </repositories> 

    <dependencies> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.9.8</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.11</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>com.github.Frameworkium</groupId> 
      <artifactId>frameworkium-core</artifactId> 
      <version>2.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-remote-driver</artifactId> 
      <version>3.0.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.53.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-server</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
     <testSourceDirectory>src/test/java</testSourceDirectory> 
     <resources> 
      <resource> 
       <directory> 
        src/main/resources 
       </directory> 
      </resource> 
     </resources> 
    </build> 


    <profiles> 
     <profile> 
      <id>tests</id> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
      <build> 

       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-compiler-plugin</artifactId> 
         <version>3.5.1</version> 
         <configuration> 
          <source>1.8</source> 
          <target>1.8</target> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-surefire-plugin</artifactId> 
         <version>2.19.1</version> 
         <configuration> 
          <parallel>methods</parallel> 
          <threadCount>${threads}</threadCount> 
          <systemProperties> 
           <screenshotDirectory> 
            ${project.build.directory}/screenshots 
           </screenshotDirectory> 
           <allure.issues.tracker.pattern> 
            /browse/%s 
           </allure.issues.tracker.pattern> 
          </systemProperties> 
          <suiteXmlFiles> 
           <suiteXmlFile>testng.xml</suiteXmlFile> 
          </suiteXmlFiles> 
          <includes> 
           <include>**/Test*.java</include> 
           <include>**/*Tests*.java</include> 
           <include>**/*Tests.java</include> 
           <include>**/*Test.java</include> 
           <include>**/*TestCase.java</include> 
          </includes> 
          <groups>${groups}</groups> 
          <testFailureIgnore>false</testFailureIgnore> 
          <argLine> 
           -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" 
          </argLine> 
         </configuration> 
        </plugin> 
       </plugins> 

      </build> 
     </profile> 
    </profiles> 
</project> 

詹金斯日志似乎更何况我@BeforeMethod作为一个可能的故障原因,所以我将只包括这里

@BeforeMethod(
    alwaysRun = true 
) 
public static void configureBrowserBeforeTest(Method testMethod) { 
    try { 
     ((Driver)driver.get()).resetBrowser(); 
     wait.set(newDefaultWait()); 
     userAgent = determineUserAgent(); 
     initialiseNewScreenshotCapture(testMethod); 
    } catch (Exception var2) { 
     logger.error("Failed to configure browser.", var2); 
     throw new RuntimeException("Failed to configure browser.", var2); 
    } 
} 

我已经包含了构建我的配置屏幕。 Configuration screen of build

道歉,如果我错过了什么。

添加依赖

enter image description here

+0

看起来像org.openqa中的工件丢失了。检查你的Maven依赖关系树,确保它是由你的一个依赖关系带给你的。我会将所有这些Selenium依赖项标记为测试范围。同时检查包装以确保它们存在。 – duffymo

+0

感谢您的回复。很抱歉,我想提出一些基本问题,我是设立CI环境的新手。 Maven依赖关系树是Maven插件?你如何通过詹金斯检查?如果我的POM在Jenkins之外拉取依赖关系,为什么它可能会与Jenkins一起缺失?你提到检查包装以确保它们存在,能够详细说明在哪里检查?我在想你的意思是在我的C上Jenkins文件夹中的某处:?感谢帮助:) – OhAye

+0

没有检查詹金斯以外的东西。看包装。我使用IntelliJ检查依赖关系树 – duffymo

回答

1

更新

<dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>3.0.1</version> 
    </dependency> 

所以它也是在3.0.1和错误走了。感谢@duffymo的帮助。

+0

干得好。发布解决方案,即使您自己找到解决方案,也会对其他人有所帮助。 – duffymo