Maven测试,Jenkins Test Suite失败java.lang.NoClassDefFoundError -

时间:2017-01-06 10:04:15

标签: firefox jenkins selenium-webdriver maven-2

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

操作系统 - Windows Server 2012 R2 浏览器 - firefox 50.1.0 Selenium Driver - 3.0.1

詹金斯错误记录

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

詹金斯日志似乎提到我的@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

1 个答案:

答案 0 :(得分:2)

更新了

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

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