Search code examples
bddqaf

QAF | How to pass ArrayList or Map from one step to another step


In QAF (Gerkin), I want to pass map data or Array List from one step to another. I have tried following:

Step 1 (inside Step Def):

    List<Object> tdData = new ArrayList<>(data.values());
    store(tdData, "data_values");

Step 2 (inside Step Def):

   System.out.println(getBundle().getObject("data_values")); // Printing the list

   ArrayList<Object> tmpValues = getBundle().getObject("data_values"); // Throwing error
   System.out.println(tmpValues.get(0));

Able to print the list as string with "System.out.println(getBundle().getObject("data_values"));" but not able to assign the list to ArrayList. Throwing below error.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project qaf-blank-project-maven: Compilation failure
[ERROR] /Users/XXXXXXX/Downloads/60b76ff32243f233355d048b/src/test/java/com/sample/steps/steps.java:[125,57] incompatible types: java.lang.Object cannot be converted to java.util.ArrayList<java.lang.Object>

Solution

  • You need to cast object to list.

       List<Object> tmpValues = (List<Object>)getBundle().getObject("data_values"); 
    
       System.out.println(tmpValues.get(0));