Forum Discussion

PhilMT's avatar
PhilMT
Occasional Contributor
5 years ago
Solved

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:

 

  1. - Create a Groovy script which contains an array of JSON objects
  2. - Create a Test Step property.
  3. - Loop the array and in each loop:
  4. - set the property to be the current JSON object
  5. - 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

 

2 Replies