How to assert value in login response in soapUI?

后端 未结 1 1832
自闭症患者
自闭症患者 2021-01-29 05:39

I have a login request and I want to assert a value from the response.

Here is this response:



        
1条回答
  •  囚心锁ツ
    2021-01-29 06:06

    Here is the groovy script, which will log the profile, endpoints

    import com.eviware.soapui.support.XmlHolder
    import net.sf.json.groovy.JsonSlurper
    def soapResponse='''
    
       
          
             
                K07FKWNDQVMZTW4JTWZMCNFJJBTQ
                ZATO_OK
             
                       
             {"timestamp": "2015-11-30T17:05:37Z", "data": {"profile": null, "token": "1225555-sd18-4895-a037-d81ae2e273e2", "endpoints": [{"label": "app6", "branches": [{"url": "/app7/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app5"}, {"label": "app4", "branches": [{"url": "/gui/v1.0/", "name": "est", "api_version": "1.0", "label": "test"}], "appname": "gui"}, {"label": "app3", "branches": [{"url": "/app3/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app3"}, {"label": "app2", "branches": [{"url": "/app2/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app2"}, {"label": "app1", "branches": [{"url": "/app1/v1.0/", "name": "test", "api_version": "1.0", "label": "test"}], "appname": "app1"}]}, "success": true}
             
          
       
    
    '''
    def holder = new XmlHolder(soapResponse)
    def response = holder.getNodeValue('//*:response')
    def json = new JsonSlurper().parseText(response)
    log.info json.data.profile
    log.info json.data.endpoints
    

    Similarly, you may query using . and json property any value as shown above.

    For ex, to get timestamp - you may use -json.timestamp and to get token, json.data.token etc.,

    EDIT: Based comments - intended to use in script assertion to handle response dynamically.

    import com.eviware.soapui.support.XmlHolder
    import net.sf.json.groovy.JsonSlurper
    def soapResponse = messageExchange.responseContent 
    def holder = new XmlHolder(soapResponse)
    def response = holder.getNodeValue('//*:response')
    def json = new JsonSlurper().parseText(response)
    log.info json.data.profile
    log.info json.data.endpoints
    

    0 讨论(0)
提交回复
热议问题