Transfering values from a response to a property
Hi
I am new to soapui and am using the free version and am wondering if I can get some help on doing this
This is how a response looks like
<Response>
<PropertyDef>
<Property1>
<e>
<Name>Prop1-1</Name>
<ID>1</ID>
</e>
<e>
<Name>Prop1-2</Name>
<ID>2</ID>
</e>
</Property1>
<Property2>
<e>
<Name>Prop2-1</Name>
<ID>11</ID>
</e>
<e>
<Name>Prop2-2</Name>
<ID>22</ID>
</e>
</Property2>
</PropertyDef>
<Propertyvalues>
<e>
<value1>3.0</value1>
<references>
<prop1>1</prop1>
<prop2>11</prop2>
</references>
<value2>5</value2>
</e>
<e>
<value1>4.0</value1>
<references>
<prop1>1</prop1>
<prop2>22</prop2>
</references>
<value2>4</value2>
</e>
<e>
<value1>6.0</value1>
<references>
<prop1>2</prop1>
<prop2>11</prop2>
</references>
<value2>1</value2>
</e>
</Propertyvalues>
</Response>
From this response: I need to look at the values and find all the values which have the reference set to say 11 . In this case there would be two records
<e>
<value1>3.0</value1>
<references>
<prop1>1</prop1>
<prop2>11</prop2>
</references>
<value2>5</value2>
</e>
<e>
<value1>6.0</value1>
<references>
<prop1>2</prop1>
<prop2>11</prop2>
</references>
<value2>1</value2>
</e>
Then need to get the data from value1 and add them . In this example it would 3.0+6.0 = 9.0 would need to be transferred to a property to be used in a subsequent request. Is there a way to do that ?
Thanks a lot in advance
Use below script assertion for the same request.
//Define the following ; edit if required.
def expectedProp2Value = 11 def expectedKeyName = 'prop2' def keyNameToSum = 'value1' //Pass the response to parseText method def pxml = new XmlSlurper().parseText(context.response) //Find all matching element e; def alles = pxml.'**'.findAll{it.name() == expectedKeyName && it == expectedProp2Value }*.parent()*.parent() //Sum the values def result = alles.collect{ it."$keyNameToSum".text() as float }.sum() log.info "Sum of the values : $result" //If you want to use the above sum in the next request; use below context.testCase.setPropertyValue('SUM', result.toString())You can try the same online demo (till summation part, rest is specific to soapui)
In the next request, use below property expansion where the above SUM is needed. For example:
<sum>${#TestCase#SUM}</sum>