zelot
9 years agoNew 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
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"