Best way to repeatedly invoke a WebService which takes JSON as the input?
Hi,
I am trying to use SoapUI to repeatedly invoke a Web Service (which is a Test Step), but supply a different application/json as the media type each time. I do not know the best way to perform this, so my approach was:
- - Create a Groovy script which contains an array of JSON objects
- - Create a Test Step property.
- - Loop the array and in each loop:
- - set the property to be the current JSON object
- - call the Test Step which invokes the web service. The application/json of the Test Step has a reference to the property
However this fails, because a property can only take a String and not take a JSON object.
Am I approaching this problem incorrectly? Is there a better way to parameterise calling a Test Step? I considered invoking the Web Service directly from Groovy, but felt that the strengths of asserting an existing Test Step (with all of its assertions) was the correct way of doing this.
If it helps, here is my Groovy script:
def currTestCase = context.testCase; def ip = [ '[ "Id": "Setting1", "Level" : "2" ]', '[ "Id": "Setting2", "Level" : "3" ]' ]; ip.each { log.info( it ); currTestCase.setPropertyValue('myProp', it); testRunner.runTestStepByName( "Invoke User Setting") log.info(" iteration complete."); } // All tests complete. Stop
Thanks,
Phil
I think you might be able to get away without using groovy, I would suggest the following approach (this answer is only applicable for SoapUI Pro:
1. Add step, Datasource: using a Directory (containing .json files) OR JSON info: https://support.smartbear.com/readyapi/docs/testing/data-driven/types/json.html)
2. Add step, REST Request
3. Add step, Datasource loop
4. Add step, Assertions etc.