英文:
Cucumber Java: How to save diferent variables for multiple scenario outlines?
问题
我有一个问题,我不知道该如何解决,我有这个问题。
我有一个具有多个示例的场景大纲,在一个步骤中,我创建了一个特殊变量,我需要在下一个场景大纲中重复使用(例如:场景1 - 示例1与场景2示例1和场景1- 示例2与场景2-示例2)。如果只有一个示例,它可以正常工作,但如果有多个示例,它将覆盖先前的值,因为它正在执行具有其示例的场景大纲,然后立即执行第二个场景大纲。我只是在步骤定义中使用它,如下所示:
private static String specialVariable;
specialVariable = printHelper.printTestWithDate();
我尝试将它们存储在示例中,但我无法做到,因为Cucumber不支持在示例中存储值。
此外,我不是开发人员,只是自动化测试人员,所以我对这些主题了解不多。但如果有人可以帮助我,我将非常感激。
英文:
I have 1 issue which i dont know how to do i have this problem.
I have Scenario outline with multiple examples in one step i screate specialvariable which i need to reuse in next scenario outline(example : scenario1 - example1 with scenario2 example1 and scenario1- example2 with scenario2-example2). It is working with just one example but if i have multiple examples it will overwrite previous value becouse it is executing scenario outline with its examples and right after it is executing second one .
Im just using it like in stepdefinition:
private static String specialVariable;
specialVariable = printHelper.printTestWithDate();
I try to store them in examples but i cannot do it because cucumber does not support storing values in examples.
Also im not a developer just automation tester so i don't know much about this topics. But if someone can help me with it i will be really thankful for that.
答案1
得分: 0
已经使用哈希表找到解决方案,我创建了一个哈希表,其中存储了值和键... 键被用作Cucumber中的变量,以便控制。
public class scenarioData {
private static Map<String, String> exampleData = new HashMap<>();
public static void setExampleData(String example, String value) {
exampleData.put(example, value);
}
public static String getExampleData(String example) {
return exampleData.get(example);
}
}
英文:
already find solution with hashmap I created hashmap where i store values + keys ... keys is used as variable in cucumber to have control
`
public class scenarioData {
private static Map<String, String> exampleData = new HashMap<>();
public static void setExampleData(String example, String value) {
exampleData.put(example, value);
}
public static String getExampleData(String example) {
return exampleData.get(example);
}
}
`
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论