Search code examples
cucumberrest-assuredrest-assured-jsonpathcucumber-serenity

Scenario Outline to use different data set by passing in REST API JSON body object


We have REST APIs with JSON BODY arrays/objects. To control the data to go in the JSON file at Runtime, using testdata.properties file where defining the data and calling that as below. We are using cucumber Serenity.

Testdata.properties file:

Value = 123

StepDefinition file:

@Given("^Set the \"([^\"]*)\" with \"([^\"]*)\"$")
public void set_data_parameterization (String fieldName, String Value)  {

            if (fieldName.contains("Test")) {
                jsonObjectNew.getAsJsonObject("TestInfo").add("Value",
                        gson.toJsonTree(Value));
            }

    System.err.println("Test value fetched from the Scenario outline");

}

JSON File:

{
"TestInfo": {
    "Test123": 3,
    "Value": 50 // this value to be replaced
}  
}

.feature file:

Scenario Outline:: 
1. Testing data parameterize

Given Set the URL for "Test" as "base" 
And Set the "Test" with "Value"

Examples:
|Value|
|700|
|710|

If calling the variable data from .properties file works fine, however if want to have different sets of data to be executed for the same scenario. How can it be achieved. Tried with Examples in feature file, but when run the file as cucumbertest>getting the actual payload value which is 50. It is not replacing with 700/710.

Please guide.


Solution

  • Able to get values as expected now, the issue was I was trying as "String" (ex: "Values"). When tried as in .feature file and rest of the code is similar. Able to get values iterated of given Examples.