bdddata-drivenqaf

QAF | In Data driven testing, retrieving csv data row directly inside StepDef


In my setup using QAF Gerkin, I have an 80+ data column in the test data file which is very difficult to pass all the columns in steps using "<data_column>". I would like to retrieve all the column data directly in my StepDef according to data-driven iteration. I have tried using getBundle().getString("column_name"), but it is not working.

Eg: Feature File:

 Scenario outline: UI-34_Customer Creation
    And I request api "get.sample.call" 
    And I assert api response status is "200" 
    And Test Data Retrive

    Examples: {"datafile": "data/scenarios/1622630669181.csv", "filter": '(_status==true) && (_id.equalsIgnoreCase("UI-34"))'}

StepDef:

QAFTestStep(description="Test Data Retrive")/**/
public void testDataRetrive(){
    System.out.println("============>>>>>>>==========");
    System.out.println(getBundle().getString("customer_name"));
    System.out.println("============<<<<<<<>>>>>>>==========");
}

Note: I'm able to retrive the data, if I mention the column name directly in Step.


Solution

  • Your step need to accept argument and value need to passed when called. In order to pass record/entry from data-provider you can use args[0] reference as value.

    Refer example below:

    @QAFTestStep(description="Test Data Retrive {testdata}")
    public void testDataRetrive(Map<String, Object> data){
        System.out.println("============>>>>>>>==========");
        System.out.println(data.get("customer_name"));
        System.out.println("============<<<<<<<>>>>>>>==========");
    }
    
    
    Scenario outline: UI-34_Customer Creation
        And I request api "get.sample.call" 
        And I assert api response status is "200" 
        And Test Data Retrive "${args[0]}"
    
        Examples: {"datafile": "data/scenarios/1622630669181.csv", "filter": '(_status==true) && (_id.equalsIgnoreCase("UI-34"))'}
    

    Refer answer to similar question.