如何通过 pom.xml 运行的 mvn 包含多个 cucumber runner 类

Posted

技术标签:

【中文标题】如何通过 pom.xml 运行的 mvn 包含多个 cucumber runner 类【英文标题】:How to include multiple cucumber runner classes through mvn run by pom.xml 【发布时间】:2021-12-11 09:27:20 【问题描述】:

我有几个跑步者课程说 CucumberLocalTestRunner, CucumberFeatureBranchTestRunner, CucumberMasterTestRunner class 。 这些运行器类使用扩展的黄瓜选项。我使用的是黄瓜 jvm 4.4.0 版。

在 pom 文件中,我设置了与运行器类具有一对一关系的配置文件。

我将如何在 pom 文件中包含 runner 类,这样如果我运行 mvn clean verify -P local 那么只有 CucumberLocalTestRunner 会运行。

其次,我猜测扩展的繁琐选项会在重新运行失败的测试后生成合并的报告。 (即我有三个测试。第一次运行:- 两个通过,一个失败。第二次运行:- 只有失败的一个执行并通过。然后我会看到所有三个通过的报告。)

    <profile>
      <id>local</id>
      <properties>
       
      </properties>
    </profile>
    <profile>
      <id>master</id>
      <properties>
        
      </properties>
    </profile>
package selenium.runners;

import com.github.mkolisnyk.cucumber.runner.ExtendedCucumber;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumberOptions;
import cucumber.api.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(ExtendedCucumber.class)
@ExtendedCucumberOptions(
        jsonReport = "target/81/cucumber.json",
        jsonUsageReport = "target/81/cucumber-usage.json",
        usageReport = true,
        detailedReport = true,
        detailedAggregatedReport = true,
        overviewReport = true,
        overviewChartsReport = true,
        pdfPageSize = "A4 Landscape",
        toPDF = true,
        outputFolder = "target/81",
        retryCount = 2,
        threadsCount = 2)
@CucumberOptions(
    glue = "selenium.stepdefs",
    features = "src/test/resources/features/",
    plugin = "json:target/cucumber/cucumber.json", "junit:target/cucumber/cucumber.xml",
    strict = true,
    tags = "@local")
public class CucumberLocalTestRunner 

【问题讨论】:

请对此进行任何更新 【参考方案1】:

您想在插件中添加运行器类,如下所示:

    <profiles>
        <profile>
            <id>local</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.22.2</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includes>
                                <include>**/CucumberLocalTestRunner.java</include>
                            </includes>
                            <argLine>Xmx12g -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Duser.timezone=Europe/London</argLine>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>net.masterthought</groupId>
                        <artifactId>maven-cucumber-reporting</artifactId>
                        <version>5.6.0</version>
                        <executions>
                            <execution>
                                <id>execution</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <projectName>Local Run</projectName>
                                    <outputDirectory>$project.build.directory</outputDirectory>
                                    <inputDirectory>$project.build.directory</inputDirectory>
                                    <jsonFiles>
                                        <param>cucumber.json</param>
                                    </jsonFiles>
                                    <mergeFeaturesById>false</mergeFeaturesById>
                                    <mergeFeaturesWithRetest>false</mergeFeaturesWithRetest>
                                    <checkBuildResult>false</checkBuildResult>
                                    <buildNumber>1</buildNumber>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo message="Cucumber execution complete. Reports are available in $project.build.directory/cucumber-html-reports/feature-overview.html"/>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
   </profiles>

然后对每个配置文件重复,选择要与其他配置文件一起运行的插件等。

【讨论】:

以上是关于如何通过 pom.xml 运行的 mvn 包含多个 cucumber runner 类的主要内容,如果未能解决你的问题,请参考以下文章

从npm 角度理解 mvn 的 pom.xml

如何使用 mvn -f 打包 pom.xml 在文件夹树中存在两个文件夹?

我可以通过 maven 运行特定的 testng 测试组吗?

mvn简单命令

pom.xml配置,针对mvn clean install -P参数(环境参数)打包

在 mvn deploy 之前将变量值应用于 Pom.xml [关闭]