Forum Discussion

pn's avatar
pn
Visitor
8 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
    8 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{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) 

    http://ideone.com/Rk6gdz

     

     

     

    In the next request, use below property expansion where the above SUM is needed. For example:

     

    <sum>${#TestCase#SUM}</sum>