我有两个方案A和B。我将'A'方案的字段输出值存储在变量中。现在,我必须在场景“ B”中使用该变量。如何在Cucumber Java中将变量及其值从一种情况传递到另一种情况
最佳答案
尚不清楚这些方案的步骤定义是否在单独的类中,但我认为它们是相同的,并且ScenarioA中的步骤是在B中的步骤之前执行的。
public class ScenarioA {
public static String getVariableYouWantToUse() {
return variableYouWantToUse;
}
private static String variableYouWantToUse;
Given("your step that expects one parameter")
public void some_step(String myVariable)
variableYouWantToUse = myVariable;
}
然后在方案B中。
public class ScenarioB {
Given("other step")
public void some_other_step()
ScenarioA.getVariableYouWantToUse();
}