Forum Discussion

Leonidaas's avatar
Leonidaas
New Contributor
14 years ago

XPath doesnt work probably??

Hi all,
hope someone can Help me solving my Problem with getting the right XPath for a special case in my GroovyScript Test Step.
After calling the Request and gettin a Response i got the GroovyScript Test Step.
I try to Check if there appears this ErrorMsg("Nothing in there.") and do something then.
I tried nearly every possible XPath for //SOAP-ENV:Fault/detail/CommandCustomerDataRequestFailure/errorMsg but cant it.
Log.info with this Path gives me a Null Message.

I have this SOAP-Response in ErrorCase:
------------------------------
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">FaultMsg</faultstring>
<detail>
<CommandCustomerDataRequestFailure xmlns="http://XXX/YY">
<ads>401413</ads>
<port>0-1-5</port>
<errorMsg>Nothing in there.</errorMsg>
</CommandCustomerDataRequestFailure>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

-----------------------------------
Groovy:
------------------------------------
//all the def stuff
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "Request1#Response" )
}
def getResponseFilename(name) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('yyyyMMdd-kkmmssms')
shortDate = dateFormat.format(date)
respFilename = shortDate + "-" + name + "-response.xml"
}
// closure referes to Drucken.call
def Drucken ={
....
....
....
....
}
//if-else content
if (context.expand('${Request1#Response#//SOAP-ENV:Fault/detail/CommandCustomerDataRequestFailure/errorMsg')=="Nothing in there.")
{
Drucken.call( 'C:/nothingthere' )
log.info "Nothing there"
}
else
{
Drucken.call( 'C:/!Error' )
log.info "Error"
}

---------------------------------
I use soapUI 3.6.1 non-pro.

2 Replies

  • Hi,

    Try capturing the XPath value in a variable first and then compare it.
    I hope following code snippet helps:

    def errMsg = context.expand( '${Request1#Response#declare namespace ns1=\'http://XXX/YY\'; //detail[1]/ns1:CommandCustomerDataRequestFailure[1]/ns1:errorMsg[1]}' )
    log.info errMsg

    if(errMsg == "Nothing in there.")
    {
    log.info "--Your code--"
    }



    Regards,