Cucumber 选项未从 mvn cli 命令运行标签方案

问题描述

我想使用以下命令从我的功能文件中运行特定场景。

mvn test -Dcucumber.options="--tags @Smoke-Login"

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.version}</version>
                <configuration>
                    <includes>
                        <include>**/TestRunner.java</include>
                    </includes>
                    <parallel>methods</parallel>
                    <threadCount>4</threadCount>
                    <useUnlimitedThreads>false</useUnlimitedThreads>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

以下是我从 pom.xml 运行套件的运行文件

@RunWith(Cucumber.class)
@CucumberOptions(
        publish = true,features = "classpath:features",glue = "stepDefinations",plugin = {"junit:target/cucumber-results.xml","rerun:target/rerun.txt","pretty","json:target/cucumber-reports/CucumberTestReport.json"},tags="@QA53",monochrome = true
)
public class TestRunner {

    @BeforeClass
    public static void setup(){
        String os = System.getProperty("os.name").toLowerCase();
        if (os.contains("mac")) {
            PropertyConfigurator.configure(System.getProperty("user.dir")+"/src/test/resources/log4j.properties");
        }
        else {
            PropertyConfigurator.configure(FileReader.getInstance().getConfigReader().getlog4jpath());
        }
    }

    @AfterClass
    public static void writeExtentReport() {
        String os = System.getProperty("os.name").toLowerCase();
        if (os.contains("mac")) {
        }
        else {
        }
    }
}

这是我在下图中的文件结构。

enter image description here

解决方法

如果您使用 a recent version of Cucumber (> 5.0),则语法为 cucumber.filter.tags=@Smoke-Login

,

您应该在 POM 文件中提到的运行文件中指定此功能文件。并且功能文件应该具有您要执行的场景的标签@Smoke-Login。 然后你就可以使用下面的命令运行

mvn test -Dcucumber.options="--tags -@Smoke-Login"