Forum Discussion

steve2ea's avatar
steve2ea
New Contributor
7 years ago

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

(Reposted from Pro forum)

 

I need to construct a simple test harness using SOAPUI Open Source version 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  Open Source 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"

 

I gather I can do this using an XML Data Source test step but if I understand correctly that is only available in the Pro version.

 

Is there a way using the Open Source version 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.