captainfranz
12 years agoOccasional Contributor
Write HTTP request programmatically
I am using SoapUI to generate some JSON data with a Groovy script and then send them with an HTTP request.
Let's say that my data is in a list, such as:
What I do at this point is to write each value as a TestCase property and then read those out from my HTTP request.
In the Groovy script:
And in my HTTP request (with JSON data):
Obviously this is not the best way of doing things, as I have a lot of repeated code. Is there a way to either write a programmatic loop in the HTTP request or to write the HTTP request programmatically from a Groovy script to avoid this kind of problem?
Let's say that my data is in a list, such as:
ids = ["id1", "id2", "id3"]
What I do at this point is to write each value as a TestCase property and then read those out from my HTTP request.
In the Groovy script:
for (i=0;i<ids.length; i++) {
testCase.setPropertyValue("id" + i, id)
}
And in my HTTP request (with JSON data):
{"sessionId": "${#TestCase#id0}"}
{"sessionId": "${#TestCase#id1}"}
{"sessionId": "${#TestCase#id2}"}
Obviously this is not the best way of doing things, as I have a lot of repeated code. Is there a way to either write a programmatic loop in the HTTP request or to write the HTTP request programmatically from a Groovy script to avoid this kind of problem?