老师,我的jenkins配置运行后,总是执行imooc工程目录下的TestngCase.java,并没有如期望的那样去执行textng.xml的case,请问如何在jenkins里面管理运行那些case?
我附上了jenkins配置截图,textng.xml, Pom.xml和Jenkins Console output
Jenkins配置截图
Testng.xml(在eclipse里点击右键运行是成功的)
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" >
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"></listener>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"></listener>
<listener class-name="com.mushishi.immoc.util.TestCaseReport"></listener>
<listener class-name="com.mushishi.imooc.TestNGListennerSendEmail"></listener>
</listeners>
<parameter name="browser" value="chrome" /><!-- 全Suite的参数 -->
<test name="Test1">
<parameter name="url" value="http://www.imooc.com" />
<parameter name="username" value="xxxx@hotmail.com" />
<parameter name="password" value="xxxxx" />
<parameter name="userInfo" value="慕仰0274710" />
<classes>
<class name="com.mushishi.imooc.runcase.LoginCases">
<methods>
<include name="testLoginSuccess"></include>
</methods>
</class>
</classes>
</test>
<test name="Test2">
<parameter name="url" value="http://www.imooc.com" />
<parameter name="username" value="xxxxx@hotmail.com" />
<parameter name="password" value="xxxxx" />
<parameter name="userInfo" value="慕仰0274710" />
<classes>
<class name="com.mushishi.imooc.runcase.LoginCases">
<methods>
<include name="testLoginEmailError"></include>
</methods>
</class>
</classes>
</test>
<test name="Test3">
<parameter name="url" value="https://coding.imooc.com/class/414.html" />
<parameter name="coursename" value="2020 重学c++" />
<classes>
<!-- <class name="com.mushishi.imooc.SeleniumMaven"/> -->
<class name="com.mushishi.imooc.runcase.CourseCase">
<methods>
<include name="testAddCourseSuccess"></include>
<include name="testAlreadyBuy"></include>
<include name="testAlreadyLogin"></include>
</methods>
</class>
</classes>
</test>
<test name="sure">
<parameter name="url" value="https://order.imooc.com/pay/confirm/goods_ids/1-414"/>
<classes>
<class name="com.mushishi.imooc.runcase.SureSubmitCase" >
<methods>
<include name="SureSubmit" ></include>
<include name="LoginSureSubmit" ></include>
</methods>
</class>
</classes>
</test><!-- Test -->
</suite> <!-- Suite -->
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.mushishi</groupId>
<artifactId>imooc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>imooc</name>
<!-- FIXME change it to the project's website -->
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency> -->
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-email/commons-email -->
<dependency>
<groupId>commons-email</groupId>
<artifactId>commons-email</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Jenkins ConSole Output
Console Output
Established TCP socket on 49607
<=[JENKINS REMOTING CAPACITY]=>channel started
Executing Maven: -B -f C:/eclipse/eclipse-workspace/imooc\pom.xml install
[INFO] Scanning for projects…
[INFO]
[INFO] -------------------------< com.mushishi:imooc >-------------------------
[INFO] Building imooc 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.testng:testng:jar:5.14.3 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.testng:testng:jar:5.14.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.testng:testng:jar:5.14.5 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.beust:jcommander:jar:1.66 is missing, no dependency information available
[WARNING] The artifact commons-email:commons-email:jar:1.1 has been relocated to org.apache.commons:commons-email:jar:1.1
[INFO]
[INFO] — maven-resources-plugin:3.0.2:resources (default-resources) @ imooc —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\eclipse\eclipse-workspace\imooc\src\main\resources
[INFO]
[INFO] — maven-compiler-plugin:3.8.0:compile (default-compile) @ imooc —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-resources-plugin:3.0.2:testResources (default-testResources) @ imooc —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\eclipse\eclipse-workspace\imooc\src\test\resources
[INFO]
[INFO] — maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ imooc —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-surefire-plugin:2.22.1:test (default-test) @ imooc —
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
this is BeforeTest
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 2171
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1596628574.107][WARNING]: This version of ChromeDriver has not been tested with Chrome version 84.
Aug 05, 2020 7:56:16 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
this is BeforeMethod
this is a f test case
this is AfterMethod
this is BeforeMethod
登录失败
登录失败
登录失败
this is AfterMethod
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 39671
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1596628607.190][WARNING]: This version of ChromeDriver has not been tested with Chrome version 84.
Aug 05, 2020 7:56:49 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
第一个case before
[DEBUG] 2020-08-05 07:56:56,696 method:com.mushishi.imooc.TestngCase.test01(TestngCase.java:38)
邮箱信息
第1个case
第一个case after
第一个case before
[ERROR] 2020-08-05 07:56:56,854 method:com.mushishi.imooc.TestngCase.test02(TestngCase.java:45)
错误的邮箱信息
com.mushishi.imooc.TestngCase@a1153bc
com.mushishi.imooc.TestngCase@a1153bc
this is AfterTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[ERROR] There are test failures.
Please refer to C:\eclipse\eclipse-workspace\imooc\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
There was an error in the forked process
class com.mushishi.imooc.TestngCase cannot be cast to class com.mushishi.imooc.runcase.BaseCase (com.mushishi.imooc.TestngCase and com.mushishi.imooc.runcase.BaseCase are in unnamed module of loader ‘app’)
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
class com.mushishi.imooc.TestngCase cannot be cast to class com.mushishi.imooc.runcase.BaseCase (com.mushishi.imooc.TestngCase and com.mushishi.imooc.runcase.BaseCase are in unnamed module of loader ‘app’)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:656)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1183)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.jvnet.hudson.maven3.launcher.Maven35Launcher.main(Maven35Launcher.java:130)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at jenkins.maven3.agent.Maven35Main.launch(Maven35Main.java:178)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:139)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:70)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService1.call(InterceptingExecutorService.java:72)atjava.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)atjava.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)atjava.base/java.util.concurrent.ThreadPoolExecutor1.call(InterceptingExecutorService.java:72)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor1.call(InterceptingExecutorService.java:72)atjava.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)atjava.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)atjava.base/java.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
[JENKINS] Recording test results
hudson.AbortException: Test reports were found but none of them are new. Did leafNodes run?
For example, C:\eclipse\eclipse-workspace\imooc\target\surefire-reports\TEST-TestSuite.xml is 17 hr old
at hudson.tasks.junit.TestResult.parse(TestResult.java:266)
at hudson.tasks.junit.TestResult.parse(TestResult.java:231)
at hudson.maven.reporters.SurefireArchiver.postExecute(SurefireArchiver.java:143)
at hudson.maven.Maven3Builder$MavenExecutionListener.recordMojoEnded(Maven3Builder.java:619)
at hudson.maven.Maven3Builder$MavenExecutionListener.mojoSucceeded(Maven3Builder.java:600)
at hudson.maven.Maven3Builder$JenkinsEventSpy.onEvent(Maven3Builder.java:303)
at org.apache.maven.eventspy.internal.EventSpyDispatcher.onEvent(EventSpyDispatcher.java:104)
at org.apache.maven.eventspy.internal.EventSpyExecutionListener.mojoSucceeded(EventSpyExecutionListener.java:131)
at org.apache.maven.lifecycle.internal.DefaultExecutionEventCatapult.fire(DefaultExecutionEventCatapult.java:87)
at org.apache.maven.lifecycle.internal.DefaultExecutionEventCatapult.fire(DefaultExecutionEventCatapult.java:42)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:218)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.jvnet.hudson.maven3.launcher.Maven35Launcher.main(Maven35Launcher.java:130)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at jenkins.maven3.agent.Maven35Main.launch(Maven35Main.java:178)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:139)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:70)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
[INFO]
[INFO] — maven-jar-plugin:3.0.2:jar (default-jar) @ imooc —
[INFO]
[INFO] — maven-install-plugin:2.5.2:install (default-install) @ imooc —
[INFO] Installing C:\eclipse\eclipse-workspace\imooc\target\imooc-0.0.1-SNAPSHOT.jar to C:\Windows\system32\config\systemprofile.m2\repository\com\mushishi\imooc\0.0.1-SNAPSHOT\imooc-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\eclipse\eclipse-workspace\imooc\pom.xml to C:\Windows\system32\config\systemprofile.m2\repository\com\mushishi\imooc\0.0.1-SNAPSHOT\imooc-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.656 s
[INFO] Finished at: 2020-08-05T07:56:58-04:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data