我在groovy代码中使用cucumber-java。我更喜欢cucumber-java而不是cucumber-groovy,因为我可以像运行普通的老式JUnit测试一样运行测试。但是,cucumber生成的步骤定义模板是java风格的。取而代之的是,我想要一种时尚的风格。例如,在java风格中,您将得到如下内容:
@When("^an HTTP GET request is sent to obtain config.xml of \"([^\"]*)\"$")
public void an_HTTP_GET_request_is_sent_to_obtain_config_xml_of(String arg1) throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}由于我使用的是groovy,所以我希望得到如下内容
@When(/^an HTTP GET request is sent to obtain config.xml of "([^"]*)"$/)
void 'an HTTP GET request is sent to obtain config.xml of'(String arg1) {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}我正在考虑实现这样一个功能。基本上,我的想法是在cucumber.api.CucumberOptions中添加一个新字段,可能名为templateLanguage。当这个新字段等于groovy时,groovy样式的模板将被拆分。这可能会涉及cucumber.runtime.java.JavaSnippet.template()中的if语句,例如
if( runtimeOptions.getTemplateLanguage().toLowerCase().equals('groovy') ) {...}
但是,我的问题是:如何获得传入的runtimeOptions的引用,如下所示
@CucumberOptions(
format = ["pretty", "html:build/cucumber"],
features="src/test/resources/cucumber_features/api/job_view.feature",
glue=['com.yahoo.adcd.jenkins.tests.smoke.api.cucumber.job.view'],
strict = true
)非常感谢!
发布于 2018-09-12 23:50:20
在这种情况下,您需要编写自己的引导类,因为RuntimeOptions没有依赖项注入。一个很好的起点是看一下cucumber.api.cli.Main。您需要创建自己的类来扩展RuntimeOptions,然后在其中添加您的逻辑。
但是,此解决方案将不再允许您使用CucumberOptions注释运行应用程序。如果您确实喜欢使用注释,则还需要实现您自己的自定义注释并覆盖RuntimeOptionsFactory以使用您的注释,然后在新的主类中使用该工厂来动态创建运行时。
https://stackoverflow.com/questions/22224952
复制相似问题