目标: 我需要完成/成功的Maven构建周期,以便生成报告。 但是如何在Jenkins中显示测试失败而不取消构建?
-步骤:
-想要:
-为什么? :
这是我的控制台输出上下文。
10:51:16
10:51:16 ===============================================
10:51:16 TEST FRAMEWORK DEMO 1 PASS 1 FAIL
10:51:16 Tests run: 2, Failures: 1, Skips: 0
10:51:16 ===============================================
10:51:16
10:51:16 [ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 5.405 s <<< FAILURE! - in TestSuite
10:51:16 [ERROR] com.demo.runnertypes.DemoTest.runScenario Time elapsed: 1.473 s <<< FAILURE!
10:51:16 org.openqa.selenium.InvalidSelectorException:
10:51:16 invalid selector: Unable to locate an element with the xpath expression //input[@id='password']invalidXpath because of the following error:
10:51:16 SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//input[@id='password']invalidXpath' is not a valid XPath expression.
10:51:16 (Session info: headless chrome=78.0.3904.97)
10:51:16 For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
10:51:16 Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
10:51:16 System info: host: 'fmdat01ap01.unix.ctcwest.ctc', ip: '192.168.241.251', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1062.4.1.el7.x86_64', java.version: '1.8.0_212'
10:51:16 Driver info: org.openqa.selenium.chrome.ChromeDriver
10:51:16 Capabilities [{networkConnectionEnabled=false, chrome={chromedriverVersion=77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}), userDataDir=/tmp/.com.google.Chrome.kiacKj}, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss and notify, strictFileInteractability=false, platform=LINUX, proxy=Proxy(), goog:chromeOptions={debuggerAddress=localhost:33385}, acceptInsecureCerts=false, browserVersion=78.0.3904.97, browserName=chrome, javascriptEnabled=true, platformName=LINUX, setWindowRect=true}]
10:51:16 Session ID: d6c2fbc4cbbd341cf6ef05609cb1e7a0
10:51:16 *** Element info: {Using=xpath, value=//input[@id='password']invalidXpath}
10:51:16
10:51:16 [INFO]
10:51:16 [INFO] Results:
10:51:16 [INFO]
10:51:16 [ERROR] Failures:
10:51:16 [ERROR] com.demo.runnertypes.DemoTest.runScenario
10:51:16 [INFO] Run 1: PASS
10:51:16 [ERROR] Run 2: DemoTest.runScenario » InvalidSelector invalid selector: Unable to locate an e...
10:51:16 [INFO]
10:51:16 [INFO]
10:51:16 [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
10:51:16 [INFO]
10:51:16 [ERROR] There are test failures.
10:51:16
10:51:16 Please refer to /home/fmdigi/data/jenkins/workspace/CucumberTest/target/surefire-reports for the individual test results.
10:51:16 Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
10:51:16 [INFO]
10:51:16 [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ testframework ---
10:51:17 [INFO] Building jar: /home/fmdigi/data/jenkins/workspace/CucumberTest/target/testframework-1.0-SNAPSHOT.jar
10:51:17 [INFO]
10:51:17 [INFO] --- cluecumber-report-plugin:2.3.1:reporting (report) @ testframework ---
10:51:17 [INFO] ------------------------------------------------------------------------
10:51:17 [INFO] Cluecumber Report Maven Plugin, version 2.3.1
10:51:17 [INFO] ------------------------------------------------------------------------
10:51:17 [INFO] - source JSON report directory : /home/fmdigi/data/jenkins/workspace/CucumberTest/target/cucumber-report
10:51:17 [INFO] - generated HTML report directory : test-report/generated-cluecumber-report
10:51:17 [INFO] ------------------------------------------------------------------------
10:51:17 [INFO] - fail pending/undefined scenarios : false
10:51:17 [INFO] - expand before/after hooks : true
10:51:17 [INFO] - expand step hooks : false
10:51:17 [INFO] - expand doc strings : false
10:51:17 [INFO] - page title : Cluecumber Report
10:51:17 [INFO] - colors (passed, failed, skipped) : #28a745, #dc3545, #ffc107
10:51:17 [INFO] ------------------------------------------------------------------------
10:51:17 [INFO] => Cluecumber Report: test-report/generated-cluecumber-report/index.html
10:51:17 [INFO] ------------------------------------------------------------------------
10:51:17 [INFO] BUILD SUCCESS
10:51:17 [INFO] ------------------------------------------------------------------------
10:51:17 [INFO] Total time: 10.711 s
10:51:17 [INFO] Finished at: 2019-11-19T10:51:47-07:00
10:51:18 [INFO] Final Memory: 28M/571M
10:51:18 [INFO] ------------------------------------------------------------------------
10:51:18 [htmlpublisher] Archiving HTML reports...
10:51:18 [htmlpublisher] Archiving at BUILD level /home/fmdigi/data/jenkins/workspace/CucumberTest/test-output/HtmlReport to /var/lib/jenkins/jobs/CucumberTest/builds/15/htmlreports/ExtentHtml_Report
10:51:18 [htmlpublisher] Archiving at BUILD level /home/fmdigi/data/jenkins/workspace/CucumberTest/test-report/generated-cluecumber-report to /var/lib/jenkins/jobs/CucumberTest/builds/15/htmlreports/Test_Report
10:51:18 Collecting metadata...
10:51:18 Metadata collection done.
10:51:18 Finished: SUCCESS
POM.xml构建阶段
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<extent.reporter.html.start>true</extent.reporter.html.start>
<extent.reporter.html.out>test-output/HtmlReport/ExtentHtml.html</extent.reporter.html.out>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-report-plugin</artifactId>
<version>${cluecumber-report.version}</version>
<executions>
<execution>
<id>report</id>
<phase>post-integration-test</phase>
<goals>
<goal>reporting</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceJsonReportDirectory>${project.build.directory}/cucumber-report</sourceJsonReportDirectory>
<generatedHtmlReportDirectory>test-report/generated-cluecumber-report</generatedHtmlReportDirectory>
<expandBeforeAfterHooks>true</expandBeforeAfterHooks>
</configuration>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>${maven-download-plugin.version}</version>
<executions>
<execution>
<id>install-chrome-driver-linux64</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>
https://chromedriver.storage.googleapis.com/${chromedriver-dep.version}/chromedriver_linux64.zip
</url>
<unpack>true</unpack>
<outputDirectory>${basedir}/drivers/linux/64bit/</outputDirectory>
</configuration>
</execution>
<execution>
<id>install-chrome-driver-windows</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>
https://chromedriver.storage.googleapis.com/${chromedriver-dep.version}/chromedriver_win32.zip
</url>
<unpack>true</unpack>
<outputDirectory>${basedir}/drivers/windows/</outputDirectory>
</configuration>
</execution>
<execution>
<id>install-chrome-driver-osx</id>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>
https://chromedriver.storage.googleapis.com/${chromedriver-dep.version}/chromedriver_mac64.zip
</url>
<unpack>true</unpack>
<outputDirectory>${basedir}/drivers/osx/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:1)
我将所有Selenium测试放在一个单独的项目中,与其他代码分开。如果不是您这种情况,则以下内容可能会破坏您的构建!
关闭Surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
并替换为Failsafe plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
请注意,版本故意相同!
故障安全插件旨在运行集成测试,而Surefire插件旨在运行单元测试。选择(failsafe)这个名称既是因为它是surefire的同义词,又因为它暗示了当它失败时,它是以安全的方式这样做的。
这意味着当集成测试失败时,构建将继续进行,并将运行您在<phase>post-integration-test</phase>
中正确定义的报告。
为了使Failsafe接受您的测试,您可以将所有内容从*Test
重命名为*IT
,也可以配置Failsafe插件来选择您的测试,here说明。请注意,故障安全的几乎所有配置都与Surefire相同。您可能还需要阅读TestNG configuration section。
您仍将像以前一样运行所有内容,并使用mvn clean verify
。
詹金斯(Jenkins)所做的一件秘密事情是,它使用testFailureIgnore flag覆盖了如何处理集成测试失败。 Jenkins会覆盖默认行为,并且不会将构建标记为失败(红色图标)。因此,对于詹金斯,您必须将其重新设置。可以在您的pom中使用配置<testFailureIgnore>false</testFailureIgnore>
轻松完成此操作,或者在Jenkins中将MAVEN_OPTS
设置为-Dmaven.test.failure.ignore=false
。
答案 1 :(得分:0)
使用JUnit插件-通过Publish JUnit test result report
-将构建图标显示为黄色/红色,具体取决于我想要的配置。