我正在尝试获取“场景大纲”下的“示例”中处理的当前行数。如何获取步骤定义中的当前行数?我不想在示例中传递数字。有什么办法吗?
Scenario Outline:
When the name is entered as "<fruit>" <days>
Examples:
|fruit|days|
|Apple|10|
|Orange|12|
|Guava|3|
...
在步骤定义中,我希望将行处理为 1,2,3,...(代替 XXXXX)。
@When("^the name is entered as \"([^\"]*)\" ([^\"]*)$")
public void the_name_is_entered_as(String fruitName, int days) throws Throwable {
System.out.println("Current Row processsed is: "+XXXXXXX)
}
最佳答案
我能想到的最好的方法(这不是很漂亮)是自己计算幕后的行数:
private static int rowIndex = 0;
@When("^I enter the name as \"([^\"]+)\"$")
public void i_enter_the_name_as(String fruit) {
rowIndex++;
// now you can use it in this and subsequent steps
}
仅当“我输入名称为”仅在单个场景大纲中使用时,此功能才有效。如果您想在多个场景中使用它,我能想到的最好的办法就是在不同的场景中重置计数器。
关于java - 如何判断 Cucumber-JVM 中某个步骤正在操作表的哪一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39217046/