Jenkins-在测试失败时查看任何失败图标,即使构建通过

Jenkins-在测试失败时查看任何失败图标,即使构建通过,jenkins,Jenkins,目标: 我需要maven构建周期完成/成功,以便生成报告。 但是我怎样才能在Jenkins中显示测试失败而不取消构建呢 -步骤: 清洁验证 试运行 see的测试方法通过或失败 生成成功后,将生成报告。 -想要: 在Jenkins中-尽管构建成功,但如果TestNg测试失败,则显示红色图标。 -为什么 我不想每天都看这份报告,只是为了看看有没有失败。 快速浏览Jenkins仪表板,查看是否存在故障。 这是我的上下文控制台输出 10:51:16 10:51:16 =================

目标: 我需要maven构建周期完成/成功,以便生成报告。 但是我怎样才能在Jenkins中显示测试失败而不取消构建呢

-步骤:

清洁验证 试运行 see的测试方法通过或失败 生成成功后,将生成报告。 -想要:

在Jenkins中-尽管构建成功,但如果TestNg测试失败,则显示红色图标。 -为什么

我不想每天都看这份报告,只是为了看看有没有失败。 快速浏览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
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>

我的所有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>
并替换为:

请注意,这些版本有意相同

发件人:

故障保护插件设计用于运行集成测试,而Surefire插件设计用于运行单元测试。之所以选择failsafe这个名称,是因为它是surefire的同义词,也因为它意味着当它发生故障时,它会以安全的方式进行操作

这意味着,当集成测试失败时,构建将继续,并将运行您在集成后测试中正确定义的报告

为了使故障保护能够拾取您的测试,您可以将所有内容从*Test重命名为*IT,或者配置故障保护插件来拾取您的测试,解释道。请注意,几乎所有故障保护配置都与Surefire相同。您可能还想阅读

使用:mvn clean verify,您仍然可以像以前一样运行所有内容


Jenkins所做的一件秘密事情是,它使用。Jenkins会覆盖默认行为,不会用红色图标将构建标记为失败。所以对詹金斯来说,你必须把它放回去。在pom中,如果配置为false,或者在Jenkins中,如果将MAVEN_OPTS设置为-Dmaven.test.failure.ignore=false,则可以轻松完成此操作。

使用JUnit插件-通过发布JUnit测试结果报告-根据我想要的配置将构建图标设置为黄色/红色

显示pom的重要部分:您使用什么插件运行测试,您使用什么插件生成报告,以及它们的配置。@SiKing TestNg。我想我可以使用Jenkins中的TestNg插件。@SiKing还添加了POM@SiKing不幸的是,提议的解决方案对我不起作用。评论了任何surefire插件,只使用了故障保护-当构建失败时,不会生成报告。
<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>