Is there any way to prepare json file from .feature file in BDD?
I am trying to create json file where input source of data is .feature file
Feature: Testing a REST API
Scenario: Create student account using post method
Given api is up and running for post method
When i create json with below valuesand hit rest api
| Student_id |Name | CityName | State |PostCode |Tel |
| 0101 |Andrew | Leeds | | SO143FT | 345345345345 |
| 0102 |Smith | NewCastle | | SO143LN | 345345345345 |
Then Status is 201
Below is the sample json file.
{
"Student_id": 0101,
"Name": "test",
"CityName": "test",
"State": "TT",
"PostCode": 89098,
"Tel": "(000)- 000-0000",
}
Create a class Student with the desired fields (as in your Example table) and you can use a framework like jackson to create json from that class.
You'll need to update the Scenario Outline to take the values from the Examples-table. For instance, in Cucumber you could do the following:
When I create a student with <Student_id> and <Name> in <CityName> in <State> with <PostCode> and <Tel>
The variables marked with <> will be replaced with the values from the table.
You would then implement a StepDefinition where you create a new Student with these values. I've added a Constructor to the Student class.
You'll then need to create the http call to send the created student as Json.
To post the http call you can use a framework like RestAssured. Afaik RestAssured does not take objects, so you'lL have to generate the json from the object.
Here's an example of how to do that with jackson.
ObjectMapper mapper = new ObjectMapper(); Student student = new Student(student_id, name, cityName, state, PostCode, Tel);
//Object to JSON in String String jsonInString = mapper.writeValueAsString(user);
Then use
jsonInString
in your http call.Found solution for my problem: table is datatable in cucumber.