cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract value from xml response in script assertion

SOLVED
zelot
New Contributor

How to extract value from xml response in script assertion

Hi,

After sendig a soap request I get this as my response:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:genXXYYZZ xmlns:ns2="http://zzzzzzz.yyy.com/">
<return>
<test>
<status>OK</status>
</test>
</return>
</ns2:genXXYYZZ>
</S:Body>
</S:Envelope>

What I want to do is extract value of status in script assertion. I do this:

- click add an assertion...
- script -> script assertion and then

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.requestContent)
holder.namespaces["ns2"] = 'http://zzzzzzz.yyy.com/';
def responseId = holder.getNodeValue("//ns2:status");
log.info(responseId);

and every time I get this:

 INFO:null
1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: How to extract value from xml response in script assertion

Oh, you are trying to get data from request, but not on the response.

Here you go:

 

def Envelope=new XmlSlurper().parseText(messageExchange.request.requestContent)
def status = Envelope.Body.genXXYYZZ.return.test.status
log.info status
assert OK == status, "Status is not ok"


Regards,
Rao.

View solution in original post

4 REPLIES 4
nmrao
Community Hero

Re: How to extract value from xml response in script assertion

Oh, you are trying to get data from request, but not on the response.

Here you go:

 

def Envelope=new XmlSlurper().parseText(messageExchange.request.requestContent)
def status = Envelope.Body.genXXYYZZ.return.test.status
log.info status
assert OK == status, "Status is not ok"


Regards,
Rao.

View solution in original post

zelot
New Contributor

Re: How to extract value from xml response in script assertion

thx for your answer it almost worked. like you said I was getting data from request so it should be

 

def Envelope=new XmlSlurper().parseText(messageExchange.request.responseContent)
def status = Envelope.Body.genXXYYZZ.return.test.status
log.info status
assert OK == status, "Status is not ok"

🙂

nmrao
Community Hero

Re: How to extract value from xml response in script assertion

Ok.

 

I was not sure you wanted it out of request or from response? That's why I put the question.  

 

Anyways, glad to know.

 



Regards,
Rao.
nmrao
Community Hero

Re: How to extract value from xml response in script assertion

But note that if you are doing it on response, then use
messageExchange.response.responseContent



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors