如何在功能文件和步骤定义中未指定的情况下访问数据文件值

问题描述 投票:0回答:1

我使用 qaf-cucumber 库来场景概述测试数据和外部文件。

回购:https://github.com/qmetry/qaf-cucumber分支:cucumber-4

我想访问 TestData 文件内容,而不在功能文件步骤定义中指定为参数。

测试数据.csv

FirstName,LastName,Title,Address,City,Zip,State
TestFName1,TestLName1,Mr,TestAddress1,TestCity1,11111,TestState1
TestFName2,TestLName2,Mr,TestAddress2,TestCity2,22222,TestState2
TestFName3,TestLName3,Mr,TestAddress3,TestCity3,33333,TestState3

功能文件:

@smoke
  Scenario Outline: Register the user with the TestData File info
  Given User is in the registration page
  When user fills the registration data
  Examples:{'datafile':'resources/TestData.csv'}

步骤定义:

@Given("When user fills the registration data")
    @QAFTestStep(description="When user fills the registration data")
    public void userFillsTheRegistrationData(){

    
//Here anyway to get the TestData.csv Content
           
String fName = logic to get the FirstName //Please provide any way to get the FirstName from TestData File using QAF-Cucumber
           
String lName = logic to get the LastName
           
String title = logic to get the Title
           
String address = logic to get the Address
           
String city    = logic to get the City
           
String zip     = logic to get the Zip
           
String state.  = logic to get the State


          
System.out.println("FirstName == " + fName);
          
System.out.println("LastName == " + lName);
          
System.out.println("Title == " + title);
          
System.out.println("Address == " + address);
          
System.out.println("City == " + city);
          
System.out.println("ZIP == " + zip);
          
System.out.println("State == " + state);`


    }

**预期结果:**

FirstName == TestFName1
LastName == TestLName1
Title == Mr
Address == TestAddress1
City == TestCity1
ZIP == 11111
State == TestState1

FirstName == TestFName2
LastName == TestLName2
Title == Mr
Address == TestAddress2
City == TestCity2
ZIP == 222222
State == TestState2


FirstName == TestFName3
LastName == TestLName3
Title == Mr
Address == TestAddress3
City == TestCity3
ZIP == 33333
State == TestState3

cucumber qaf
1个回答
0
投票

你的步骤应该接受争论。例如:

这是具有多个参数的示例:

@QAFTestStep(description="When user fills the registration data with {fname} {lname} {title}, {address}, {city}-{zip} {state}")
public void userFillsTheRegistrationData(Stirng firstName, String lastName, String title, String address, String city, int zip, String state){

}

调用step时需要传递参数。您可以使用列名称作为参数。在你的情况下,它是名字,姓氏,头衔,地址,城市,邮政编码,州。

  When user fills the registration data with "${FirstName}" "{LastName}" "${Title}", "${Address}", "${City}"-"${Zip}" "${state}"

另一个选项是接受整个记录作为地图:

@QAFTestStep(description="When user fills the registration data with {fname} {lname} {title}, {address}, {city}-{zip} {state}")
public void userFillsTheRegistrationData(Map<String, Object> data){
   String firstName = (String)data.get("FirstName");
   ...
}

您可以使用 json 字符串传递地图:

  When user fills the registration data with {'FirstName':'name', ...}

使用数据提供程序时,您可以在调用步骤时使用args[0]来引用数据行。

  When user fills the registration data with "${args[0]}"
© www.soinside.com 2019 - 2024. All rights reserved.