Forum Discussion

max1965's avatar
max1965
Contributor
13 years ago

manage xml response

From the following XML response:

<LIA errorCode="6000">
<attributes>
<attr name="cliExt">
<value>0802100000</value>
</attr>
<attr name="outBoundProxy">
<value>83.175.6.7</value>
</attr>
<attr name="svcType">
<value>APT</value>
</attr>
<attr name="accessDevice">
<value>AG</value>
</attr>
<attr name="userDevice">
<value>WIFI</value>
</attr>
</attributes>
<errorMessage/>
</LIA>

with the groovy script:

import com.eviware.soapui.support.xml.XmlUtils
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
xmlResponseHolder = groovyUtils.getXmlHolder("LIR APT NAKED#ResponseAsXML")
xmlBody = new XmlSlurper().parseText(xmlResponseHolder.getXml())
errorCode = xmlBody.@errorCode
log.info errorCode

is extract the errorCode value (6000) from the response; how the script must be modified to extract the cliExt value (0802100000) ?

5 Replies


  • def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    xmlResponseHolder = groovyUtils.getXmlHolder("LIR APT NAKED#ResponseAsXML")
    xmlBody = new XmlSlurper().parseText(xmlResponseHolder.getXml())
    cliExt = ""

    xmlBody.attributes.attr.each {
    if(it.@name == 'cliExt') {
    cliExt = it
    }
    }

    log.info cliExt
  • I have a problem; this is the groovy script:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    xmlResponseHolder = groovyUtils.getXmlHolder("LIR APT NAKED#ResponseAsXML")
    xmlBody = new XmlSlurper().parseText(xmlResponseHolder.getXml())
    outBoundProxy = ""
    xmlBody.attributes.attr.each {
    if(it.@name == 'outBoundProxy') {
    outBoundProxy = it
    }
    }
    log.info outBoundProxy
    def props = testRunner.testCase.getTestStepByName( "Properties" )
    def id = props.getPropertyValue("id");
    def softswitchname = props.getPropertyValue("softswitchname");
    log.info softswitchname
    if ( softswitchname != outBoundProxy )
    {
    log.info("LIR APT NAKED - wrong softswitchname: $outBoundProxy")
    testRunner.fail( "softswitchname" )
    }

    The result of the script is the following:

    Wed Feb 27 09:24:56 CET 2013:INFO:outBoundProxy = 83.175.6.7
    Wed Feb 27 09:24:56 CET 2013:INFO:softswitchname = 83.175.6.7
    Wed Feb 27 09:24:56 CET 2013:INFO:LIR APT NAKED - wrong softswitchname: 83.175.6.7
    Wed Feb 27 09:24:56 CET 2013:ERROR:Failed with reason [softswitchname]

    I don't understand why the if test failed
  • the problems is that you tray to compare that as numbers, what you should do is to convert them as strings and try compare that:
    try this:
    if ( softswitchname.toString().equals(outBoundProxy.toString())