Forum Discussion

steve2ea's avatar
steve2ea
New Contributor
7 years ago

How to iterate through SOAP response and invoke further request on each node

I need to construct a simple test harness which invokes a 'Search Jobs' SOAP request, iterates through the XML results set and, for each Job node, invokes a further 'Get Job' SOAP request to bring back the full details of that particular Job, which I then want to append to a file.

 

I have a SOAPUI test suite which does this as two successive test steps for a single result node, but I'm not clear how to make this work as an iteration.

 

This is the sort of Groovy script I had in mind:

 

def currentUser = context.expand( '${#TestCase#currentUser}' )
def projectName = testRunner.testCase.testSuite.project.name
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def numFilesWritten = 0

// define xml response holder
def holder = groovyUtils.getXmlHolder( "Search jobs#Response" )
// define namespace
holder.namespaces["jm"] = "http://url/of/web/service"

// get the testCase
def tc = testRunner.testCase
def prop = ""
// get testStep by its name
def ts = tc.getTestStepByName('GetJob')

// loop item nodes in response message
for( job in holder.getNodeValues( "//jm:jobId" )){
   log.info "Job ID : [$job]"
   
   // then use this Job ID to pass to a further SOAP request to get the full job details
   // then append these to a file




   numFilesWritten++
}

log.info "Num Jobs = $numFilesWritten"

 

Is there a way to invoke an existing test step multiple times from this construct, or would I be better actually scripting the entire GetJob SOAP call in Groovy?

 

Any tips greatly appreciated.

2 Replies