Forum Discussion

tshanmuganathan's avatar
tshanmuganathan
New Contributor
10 years ago
Solved

Asserting using GROOVY SCRIPTING

Hi Techies,

I am a SOAP UI Beginner and I am trying to validate the response XML from a simple currency converter web service :
http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

I got the response as :
################################################################################
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>63.665</ConversionRateResult>
</ConversionRateResponse>
</soap:Body>
</soap:Envelope>
################################################################################



Now I would like to validate the response and I have written the below Groovy script. However I always get value as NULL. Can someone please help me in this regard ?

==================================================
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent );
holder.namespaces["ns"] = "http://www.webserviceX.NET/";

def responseId = holder.getNodeValue["//ns.ConversionRateResult"];

log.info responseId
==================================================

The output is always NULL. I have made so many references but couldn't get the correct solution.

Please help.
  • check this out


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
    holder.namespaces["ns"] = "http://www.webserviceX.NET/"
    def conversionRate = holder.getNodeValue("//ns:ConversionRateResult")
    log.info conversionRate

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    check this out


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
    holder.namespaces["ns"] = "http://www.webserviceX.NET/"
    def conversionRate = holder.getNodeValue("//ns:ConversionRateResult")
    log.info conversionRate
  • Thanks a lot Rao.

    Why just by changing variable name we are able to get the values.

    what is the speciality about the variable 'responseId' ??

    Can you please make me understand.
  • nmrao's avatar
    nmrao
    Champion Level 3
    That is not the reason, was only meant for right variable name. Looks you did not make the right observation for the root cause.
  • I made a close observation:
    + In my script, I terminated each line with a semicolon
    + The variable name that you have used is different from mine.

    I m really missing something here. I know I m asking a basic question here. Can you please explain the root cause ? Thanks for your patience.

    Cheers
    Shan.
  • nmrao's avatar
    nmrao
    Champion Level 3
    getNodeValue is a method, should be called with paranthesis.