Forum Discussion

kashd's avatar
11 years ago

xml response with json

Hi, I'm just starting to use soapui to test my web service
my response example
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetContextV2Response xmlns="http://myservice/Service">
<GetContextV2Result>{"ContextId":"ee218f66-0614-406d-8faf-7c1aff9fb738","PasswordExpirationDaysLeft":-1,"LoginResult":[{"RETURN_VALUE":0},{"LOGINRES":"LOGINOK"}]}</GetContextV2Result>
</GetContextV2Response>
</s:Body>
</s:Envelope>


how can i transfer ContextId into my second testStep
  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    Here is the script that can be placed after you Test Step (whose name is assumed Request)

    import groovy.json.JsonSlurper 
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "Request#Response" )
    holder.namespaces["ns"] = "http://myservice/Service"
    def result = holder.getNodeValue("//ns:GetContextV2Result")
    def slurper = new JsonSlurper()
    def json = slurper.parseText(result)
    def context = json.ContextId
    log.info "ContextId from response is : ${context}"