AutoTig AutoTig -4 years ago 205
Groovy Question

Counting response nodes in soapUI with groovy

I am trying to count response nodes and then do something over the amount of nodes.
I've tried it in the following groovy script but the count remains "0":

def collection = ["1","2","3","4"]

// get num repetitions of <SubsPlanDto> with Xpath count
def numElements = context.expand( '${QuerySubsPlanList - Request 1#Response#//count(*:QuerySubsPlanListResponse[1]/SubsPlanDtoList[1]/SubsPlanDto)}')
def collection2 = [];
// iterate and add the values to a collection
for ( i in 1..numElements.toInteger()) {
collection2.add(context.expand( '${QuerySubsPlanList - Request 1#Response#//*:QuerySubsPlanListResponse[1]/SubsPlanDtoList[1]/SubsPlanDto['+ i + ']/SubsPlanCode[1]}'))

// get the matches and differences
def matches = collection.intersect(collection2)
def fails =
fails.removeAll(matches) matches fails

The structure of the response is as follows

<ns:QuerySubsPlanListResponse xmlns:ns="http://com.ztesoft.zsmart/xsd">
<SubsPlanCode>TEST2 </SubsPlanCode>

Can anyone tell me how to count the nodes correctly?

Answer Source

context.expand() returns a String! Also, your XPath has multiple problems. You probably want:

def numElements = context.expand('${QuerySubsPlanList - Request 1#Response#count(//*:SubsPlanDto)}').toInteger()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download