如何从Java代码运行黄瓜特征文件而不是从JUnit Runner运行

bug*_*ker 4 selenium cucumber selenium-webdriver cucumber-java qaf

我想从java代码运行黄瓜功能文件.

目前我们正在运行JUnit Runner

package com.compareglobalgroup.testscript;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

    @CucumberOptions(features = { "src/test/resources/feature/BB" }, glue = { "com.compareglobalgroup.stepdefs.BB",
        "com.compareglobalgroup.cucumber.hooks" }, plugin = {
                "json:cucumberreport/json/cucumberreport.json" }, tags = { ""
                        + "@Test" })
    public class TestRunnerBB extends AbstractTestNGCucumberTests {

}
Run Code Online (Sandbox Code Playgroud)

我不想使用它,而是想使用java程序运行它,因为我想在运行时从命令行或jenkins传递标记.

Gra*_*per 7

从命令行中调用与运行黄瓜相对应的包中的Main类的静态main方法cucumber.api.cli.

public static void main(String[] args) throws Throwable {

    Main.main(new String[]{"-g", "classpath to step definition file", "Full path to feature file"});

          // My stepdefinition is inside java package at cucumber.sample.test
          // My feature file is inside src/test/resources/features/featurefile.feature

        } 
Run Code Online (Sandbox Code Playgroud)

对于其他参数,如标签或插件使用"-t","@Tags".重要的是,要素文件路径必须是最后一个选项.

顺便说一句 - 在你的例子中,你正在使用TestNG黄瓜跑步者.