Forum Discussion

pn's avatar
7 years ago

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> ...
  • nmrao's avatar
    7 years ago

    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{ == expectedKeyName && it == expectedProp2Value }*.parent()*.parent() //Sum the values def result = alles.collect{ it."$keyNameToSum".text() as float }.sum() "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: