5

我想从 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 {

}

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

4

2 回答 2

8

从命令行调用运行黄瓜对应的包中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

        } 

对于标签或插件等附加参数,请使用"-t","@Tags". 重要的是,功能文件路径必须是最后一个选项。

顺便说一句 - 在您的示例中,您使用的是 TestNG 黄瓜跑步者。

于 2017-10-19T07:46:21.340 回答
1

我会推荐qaf-gherkin你不需要使用junit或其他跑步者。您只需要指定要运行的步骤提供程序包和功能文件或目录。例如:

<test name="Gherkin-QAF-Test">
   <parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
   <parameter name="scenario.file.loc" value="resources/features" />
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
   </classes>
</test>

您可以浏览qaf-step-by-step-tutorial

于 2017-10-25T15:29:04.267 回答