质量保证金 |在数据驱动测试中,直接在 StepDef 中检索 csv 数据行

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

在我使用 QAF Gerkin 的设置中,我在测试数据文件中有一个 80 多个数据列,很难使用“”分步传递所有列。我想根据数据驱动迭代直接在我的 StepDef 中检索所有列数据。我试过使用 getBundle().getString("column_name"),但它不起作用。

例如: 功能文件:

 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("============<<<<<<<>>>>>>>==========");
}

注意:如果我在步骤中直接提及列名,我可以检索数据。

您的步骤需要接受参数,调用时需要传递值。为了从数据提供者传递 record/entry,您可以使用 args[0] 引用作为值。

参考下面的例子:

@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"))'}

参考 answer 类似问题。