Maven 测试,Jenkins 测试套件失败 java.lang.NoClassDefFoundError -

Maven test, Jenkins Test Suite failure java.lang.NoClassDefFoundError -

我正在尝试通过 Maven 运行 我的测试,但是我在构建过程中遇到错误。我在过去 2 天里尝试解决这个问题,但现在 运行 没有想法了。我已确保我的 POM 具有正确的依赖项并且测试在 Jenkins 之外工作。

OS - Windows 服务器 2012 R2 浏览器-firefox 50.1.0 Selenium 驱动程序 - 3.0.1

Jenkins 错误日志

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

Running TestSuite
[AppClassLoader@18b4aac2] 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 构建失败

[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>

Jenkins 日志似乎提到了我的 @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);
    }
}

我已经包含了构建的配置屏幕。

如有遗漏,请见谅。

添加依赖项

已更新

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

所以它也在 3.0.1 上并且错误消失了。感谢@duffymo 的帮助。