cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to repeatedly invoke a WebService which takes JSON as the input?

SOLVED
New Contributor

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

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Best way to repeatedly invoke a WebService which takes JSON as the input?

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.

 

 

View solution in original post

2 REPLIES 2
Highlighted
Occasional Contributor

Re: Best way to repeatedly invoke a WebService which takes JSON as the input?

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.

 

 

View solution in original post

New Contributor

Re: Best way to repeatedly invoke a WebService which takes JSON as the input?

Thanks - that was helpful!

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors