如何从java代码中运行黄瓜功能文件不是来自JUnit Runner
问题描述:
我想从java代码运行黄瓜功能文件。如何从java代码中运行黄瓜功能文件不是来自JUnit Runner
我们目前正在运行的形式JUnit运行
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程序使用。
答
调用包cucumber.api.cli
中Main类的静态主方法,该方法对应于从命令行运行黄瓜。
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黄瓜亚军。
答
我会推荐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>
由于走老兄非常有用的。我将来会使用它,因为我已经创建了我的框架。 – bugCracker