Maven Cucumber Reports 中构建失败时不生成报告

Posted

技术标签:

【中文标题】Maven Cucumber Reports 中构建失败时不生成报告【英文标题】:Reports are not generated when the build is failed in Maven Cucumber Reports 【发布时间】:2018-06-02 22:21:32 【问题描述】:

构建成功时报告生成成功,但是当有任何导致构建失败的失败案例时,不会生成报告。

checkBuildResult 已设置为 false

pom 文件插件

     <plugin>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <version>3.13.0</version>
        <executions>
            <execution>
                <id>execution</id>
                <phase>verify</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <projectName>Simplify360 Automation Test Report</projectName>
                    <outputDirectory>$project.build.directory/site/cucumber-reports</outputDirectory>
                    <cucumberOutput>$project.build.directory/cucumber.json</cucumberOutput>
                    <!-- <jsonFiles>
                        <param>$project.build.directory/cucumber.json</param>
                    </jsonFiles> -->
                    <!-- <parallelTesting>false</parallelTesting> -->
                    <buildNumber>8.4.1.2</buildNumber>
                    <checkBuildResult>false</checkBuildResult>
                </configuration>
            </execution>
        </executions>
    </plugin>

跑步者类如下,

  @RunWith(Cucumber.class)
    @CucumberOptions(
            features = "classpath:features",
            plugin = "pretty","json:target/cucumber.json",
            tags = "@currentTest",
            glue="helpers","stepDefinitions",
            monochrome = true
            )
    public class RunCukesTest

    

【问题讨论】:

【参考方案1】:

将以下配置添加到sure fire插件。它不会在失败后停止 maven 执行。然后它会生成报告。

<testFailureIgnore>true</testFailureIgnore>

如下所示,使用您现有的配置。

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.20</version>
      <configuration>
        <testFailureIgnore>true</testFailureIgnore>
     </configuration>
</plugin>

【讨论】:

这行得通。谢谢。我们可以将这些导出为 PDF 我不确定导出为 pdf。也许你可以在这里尝试扩展黄瓜报告mkolisnyk.github.io/cucumber-reports/pdf-export【参考方案2】:

存在相同的标志,如下所示:

<checkBuildResult>true</checkBuildResult>

<!-- Set true to fail build on test failures -->
<!-- Set false to pass build on test failures -->

您需要在配置标签中进行如下设置:

 <configuration>
        <projectName>oasys-confirmations</projectName>
        <outputDirectory>$project.build.directory</outputDirectory>
       <cucumberOutput>$project.build.directory/cucumber.json</cucumberOutput>
       <checkBuildResult>true</checkBuildResult>
</configuration>

新配置:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>3.20.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>cucumber-jvm-example</projectName>
                            <!-- output directory for the generated report -->
                            <outputDirectory>$project.build.directory</outputDirectory>
                            <!-- optional, defaults to outputDirectory if not specified -->
                            <inputDirectory>$project.build.directory/</inputDirectory>
                            <jsonFiles>
                                <!-- supports wildcard or name pattern -->
                                <param>**/*.json</param>
                            </jsonFiles>
                            <!-- optional, defaults to outputDirectory if not specified -->
                            <classificationDirectory>$project.build.directory/</classificationDirectory>
                            <classificationFiles>
                                <!-- supports wildcard or name pattern -->
                                <param>sample.properties</param>
                                <param>other.properties</param>
                            </classificationFiles>
                            <parallelTesting>false</parallelTesting>
                            <checkBuildResult>true</checkBuildResult>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

旧配置工作到 3.16.0 版本:

                 <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <configuration>
                            <testFailureIgnore>true</testFailureIgnore>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>net.masterthought</groupId>
                        <artifactId>maven-cucumber-reporting</artifactId>
                        <version>3.16.0</version>
                        <executions>
                            <execution>
                                <id>execution</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <projectName>>cucumber-jvm-example</projectName>
                                    <outputDirectory>$project.build.directory</outputDirectory>
                                    <cucumberOutput>$project.build.directory/cucumber.json</cucumberOutput>
                                    <checkBuildResult>true</checkBuildResult>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

注意如果您在此配置后遇到同样的问题,那么 1. 正常运行RunnerFile TestNG 2. 运行 Pom.xml 作为 Maven 安装。 3.检查目标文件夹是否有TagName.html文件打开查看结果。

【讨论】:

@ShubhamJain 它仅在执行“maven 安装”时生成 html 报告,仅生成 json 报告并且在作为 TestNG 测试运行时不更新 Html 报告。有什么想法吗?

以上是关于Maven Cucumber Reports 中构建失败时不生成报告的主要内容,如果未能解决你的问题,请参考以下文章

jenkins2.x版本中有cucumber reports plugin插件吗

Maven Surefire 插件没有重新运行失败的 Cucumber 测试

如何从量角器[3.0.0]和黄瓜最新版本获得cucumber-test.json

未定义步骤参考 InteliJ + Cucumber for Java + Maven 项目

xml 如何使用Maven组合GWT和Jasper Reports

需要帮助在 junit 运行中使用 cucumber、selenium、maven、TestNG 运行跨浏览器(多浏览器)测试