[英]How to tell what row of a table a step is operating on in Cucumber-JVM?
我试图在“场景大纲”下的“示例”中处理当前行计数。 如何在步骤定义中获取当前行数? 我不想在示例中传递数字。 有什么办法吗?
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
}
这仅在“我输入名称为”时才用于单个场景大纲。 如果你想在多个场景中使用它概述我能想到的最好的事情是在不同的场景中重置计数器。
private Scenario scenario;
@Before
public void before(Scenario sce) {
this.scenario = sce;
System.out.println("SCENARIO ID -- " +scenario.getId());
}
您将获得类似于场景大纲的字符串 - 功能描述; scenariooutline-description; 例子描述; rownumber + 1。
对于一个简单的场景,你会得到 - 特征描述; 情景描述。
对于场景大纲案例,您可以使用分隔符“;”进行拆分 减去1之后使用最后一部分。
这有点像黑客攻击,它依赖于此模式中剩余的方案id字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.