Search code examples
selenium-webdriverautomationcucumbercucumber-java

Cucumber Java: How to save diferent variables for multiple scenario outlines?


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.


Solution

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

    } `