Java与cucumber表达式匹配
我在外部框架中使用jvm 我需要匹配黄瓜步骤和小黄瓜句子的代码。在jvm中,如何匹配好的表达式。我需要这个,因为在V2.x.x中是regep(不是cucumber表达式) 小黄瓜:Java与cucumber表达式匹配,java,cucumber-jvm,Java,Cucumber Jvm,我在外部框架中使用jvm 我需要匹配黄瓜步骤和小黄瓜句子的代码。在jvm中,如何匹配好的表达式。我需要这个,因为在V2.x.x中是regep(不是cucumber表达式) 小黄瓜:I等待3秒。匹配@然后(“I等待{int}秒\\” 小黄瓜:I等待1秒。匹配@Then(“I等待{int}秒\\” 编辑: 我在cucumber jvm的单元测试中发现了以下内容: @Test public void unknown_target_type_does_no_transform_data_table()
I等待3秒。
匹配@然后(“I等待{int}秒\\”
小黄瓜:I等待1秒。
匹配@Then(“I等待{int}秒\\”
编辑:
我在cucumber jvm的单元测试中发现了以下内容:
@Test
public void unknown_target_type_does_no_transform_data_table() {
StepExpression expression = new StepExpressionFactory(registry).createExpression("Given some stuff:", UNKNOWN_TYPE);
List<Argument> match = expression.match("Given some stuff:", table);
assertEquals(DataTable.create(table), match.get(0).getValue());
}
@测试
public void未知\u目标\u类型\u不\u转换\u数据\u表(){
StepExpression=new StepExpressionFactory(registry).createExpression(“给定一些内容:”,未知类型);
List match=expression.match(“给定一些内容:”,table);
assertEquals(DataTable.create(table)、match.get(0.getValue());
}
解决方案是:
private static List<?> match(String expressionString, String text) {
Expression expression;
ParameterTypeRegistry parameterTypeRegistry = new ParameterTypeRegistry(Locale.ENGLISH);
expression = new CucumberExpression(expressionString, parameterTypeRegistry);
List<Argument<?>> args = expression.match(text);
if (args == null) {
return null;
} else {
List<Object> list = new ArrayList<>();
for (Argument<?> arg : args) {
Object value = arg.getValue();
list.add(value);
}
return list;
}
}
结果是:
["foo","foo"]
["foo","foo"]
[1]
[1]
[2]
[2]
null
[]
["foo",".+","demo.DemoPage-big_title","This is a demo for NORAUI.*",3]
解决办法是:
private static List<?> match(String expressionString, String text) {
Expression expression;
ParameterTypeRegistry parameterTypeRegistry = new ParameterTypeRegistry(Locale.ENGLISH);
expression = new CucumberExpression(expressionString, parameterTypeRegistry);
List<Argument<?>> args = expression.match(text);
if (args == null) {
return null;
} else {
List<Object> list = new ArrayList<>();
for (Argument<?> arg : args) {
Object value = arg.getValue();
list.add(value);
}
return list;
}
}
结果是:
["foo","foo"]
["foo","foo"]
[1]
[1]
[2]
[2]
null
[]
["foo",".+","demo.DemoPage-big_title","This is a demo for NORAUI.*",3]
这有助于创建您的方法吗?我很熟悉这个文档。这是一个用户文档。我的问题是如何进行匹配(不是作为用户,而是作为开发人员)?我想使用jvm代码中的匹配器来做其他事情。我不是在寻找cucumber-jvm的使用文档。在@MikeJRamsey56上查看,您的链接是cucumber-jvm的github主页。你能把你的想法贴出来吗?这有助于你创建方法吗?我很熟悉这个文档。这是一个用户文档。我的问题是如何进行匹配(不是作为用户,而是作为开发人员)?我想使用jvm代码中的匹配器来做其他事情。我不是在寻找cucumber-jvm的使用文档。在@MikeJRamsey56上查看,您的链接是cucumber-jvm的github主页。你能把你的信发出去吗?