How to make the REST request JSON Key's Value dynamic?
Let say, I have following request as JSON:-
{
"code":"${DataSource#code}",
"ciDate":"${Properties#StartDate}",
"coDate":"${Properties#EndDate}"
}
I want to make ciDate and coDate dynamic in the sense that the count of StartDate and EndDate could be increase or decrease.
So, I am storing it into properties as StartDate1, StartDate2, StartDate3.......So..on. Similarly EndDate1, EndDate2, EndDate2... So..on.. Now How should I pass these values automatically for ciDate and coDate respectively and get the response for each StartDate and EndDate stored at some where.
The Open Source way to do it would be to run a Groovy Script in the same Test Case as your Test Request. As an example:
def step = testRunner.testCase.getTestStepByName("My REST Test Step")
def data = [
[startDate: "01/01/2001", endDate: "02/02/2002"],
[startDate: "03/03/2003", endDate: "04/04/2004"],
[startDate: "05/05/2005", endDate: "06/06/2006"]
]
data.each {
testRunner.testCase.setPropertyValue("startDate", it.startDate)
testRunner.testCase.setPropertyValue("endDate", it.endDate)
testRunner.runTestStep( step )
log.info step.testRequest.responseContentAsString // just logging it here but you could write to file etc
}And request body as:
{ "code":"${DataSource#code}", "ciDate":"${#TestCase#startDate}", "coDate":"${#TestCase#endDate}" }
There may be easier ways to do it in Pro, but I wouldn't know about that. I mention it because you have mentioned a DataSource, which I believe is only for Pro.