Re: How to run a loop dynamically using values received in a response in SOAP UI Pro
Hi Lucian,
Thanks for the prompt response :) . I tried with script you gave, currently it is not going into while loop. Not sure what the issue is. If you can please help me on that. the result and modified script is as below
def referenceIds = []
// Get raw response
rawResponse = testRunner.testCase.testSteps["findReferenceforTypes-Delete Operation"].testRequest.response.contentAsString
log.info rawResponse //first log response
// Find all reference ids in the GetReferenceIds test step
while ( rawResponse.indexOf( "referenceID\" : ") != -1 ){
rawResponse = rawResponse.substring( rawResponse.indexOf( "referenceID\" : \"") + "referenceID\" : \"".length() )
referenceIds.add( rawResponse.substring( 0, rawResponse.indexOf( "\"" ) ) )
rawResponse = rawResponse.substring( "referenceID\" : \"".length() )
log.info referenceIds //check for referenceIds
}
// Get the current iteration
def currentIteration = testRunner.testCase.testSteps["DataSource3"].currentRow
// Iterate for each element in the referenceIds list
if (currentIteration < referenceIds.size) {
result["ReferenceId"] = referenceIds[currentIteration]
}
Result
Thu Apr 12 15:00:24 IST 2018:INFO:[{"referenceID":"e4e1c0ab62b850860162b9265c12005b","nativeSourceIDValue":"NativeSourceID762","masterID":"f126a218-38ef-4e76-bc68-470cc7d0c117","referenceTypeID":"e4e1c0ab62b850860162b9265bbe005a","targetReferenceTypeID":null},{"referenceID":"e4e1c0ab62b850860162b9265c68005c","nativeSourceIDValue":"NativeSourceID861","masterID":"7e8b57bb-4d8e-4039-9a7f-22bbb84990e0","referenceTypeID":"e4e1c0ab62b850860162b9265bbe005a","targetReferenceTypeID":null}]
Thu Apr 12 15:00:24 IST 2018:INFO:[:]
The response comes as "referenceId":"value" (no blanks between the key and value). You just have to modify the while loop as in:
// Find all reference ids in the GetReferenceIds test step while ( rawResponse.indexOf( "referenceID\":") != -1 ){ rawResponse = rawResponse.substring( rawResponse.indexOf( "referenceID\":\"") + "referenceID\":\"".length() ) referenceIds.add( rawResponse.substring( 0, rawResponse.indexOf( "\"" ) ) ) rawResponse = rawResponse.substring( "referenceID\":\"".length() ) log.info referenceIds //check for referenceIds }
Let me know if it works!