cancel
Showing results for 
Search instead for 
Did you mean: 

Asserting using GROOVY SCRIPTING

SOLVED
Highlighted
New Contributor

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.
Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Asserting using GROOVY SCRIPTING

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


Regards,
Rao.

View solution in original post

5 REPLIES 5
Community Hero

Re: Asserting using GROOVY SCRIPTING

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


Regards,
Rao.

View solution in original post

New Contributor

Re: Asserting using GROOVY SCRIPTING

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.
Community Hero

Re: Asserting using GROOVY SCRIPTING

That is not the reason, was only meant for right variable name. Looks you did not make the right observation for the root cause.


Regards,
Rao.
New Contributor

Re: Asserting using GROOVY SCRIPTING

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.
Community Hero

Re: Asserting using GROOVY SCRIPTING

getNodeValue is a method, should be called with paranthesis.


Regards,
Rao.