Forum Discussion

easyfish's avatar
easyfish
Contributor
9 years ago
Solved

how to get proerties value from layered response in Groovy script

Hello!


I am doing data-driven testing and now working on data tranferring from soapui request/response to oracle table.

With the following groovy, I can get the value of the response, then I can update the responding test data in orable table.

----
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes

def response=context.expand('${Additional#response}')
log.info response

// get the desired node value from response
def xml=new XmlHolder(response)

def r_Amount=xml.getNodeValue("//Amount")
def r_Base=xml.getNodeValue("//Base")
def r_yRate=xml.getNodeValue("//Rate")

log.info r_Amount +" "+r_Base +" "+r_Rate
-----

When the response has two layers, like below, I can only the get first <amountItem>, how can I get the values under the second <amountItem>?


<amountItems>
    <amountItem>
       <Amount>900.00</Amount>
       <Base>10000.000</Base>
       <Rate>9.000</Rate>
    </amountItem>

    <amountItem>
       <Amount>900.00</Amount>
       <Base>10000.000</Base>
       <Rate>9.000</Rate>
    </amountItem>
</amountItems>


I tried the code and get null.
def r_amountItem=xml.getNodeValue("//amountItem")
log.info r_amountItem