0

I using qaf-cucumber library for scenario outlines testdata with external files.

Repo: https://github.com/qmetry/qaf-cucumber Branch: cucumber-4

I want to access the TestData file content without specifying as parameters in feature file step definitions.

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

feature file:

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

StepDefs:

@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);`
 }

**Expected Result: **

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
asked Oct 4, 2023 at 20:10

1 Answer 1

0

Your step should accept argument. For instance:

Here is example with multiple arguments:

@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){
}

arguments needs to be passed when calling step. You can use column names as parameter. In you case it is FirstName,LastName,Title,Address,City,Zip,State.

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

another option is accepting entire record as map:

@QAFTestStep(description="When user fills the registration data with {data}")
public void userFillsTheRegistrationData(Map<String, Object> data){
 String firstName = (String)data.get("FirstName");
 ...
}

You can pass map using json string:

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

or

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

or when using data provider, you can use args[0] to refer data row while calling step.

 When user fills the registration data with "${args[0]}"
answered Oct 5, 2023 at 15:43
Sign up to request clarification or add additional context in comments.

2 Comments

Hi I tried to use the entire record as Map with cucumber but it didn't work. When user fills the registration data with {'FirstName':'fname', 'LastName' : 'lname'} @QAFTestStep(description="When user fills the registration data with") @When("When user fills the registration data with {map}") public void userFillsTheRegistrationData(Map<String, Object> data){ String firstName = (String)data.get("FirstName"); String lastName = (String)data.get("LastName"); }
refere updated answer @QAFTestStep(description="When user fills the registration data with {map}") . BTW you don't need @When

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.