Cucumber Java:如何为多个场景大纲保存不同的变量?

huangapple go评论60阅读模式
英文:

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);
}

}
`

huangapple
  • 本文由 发表于 2023年7月12日 21:13:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76670997.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定