2014-09-23 32 views
0

我在soapUI有2個依賴步驟。我想自動使用第一個響應中返回的值作爲第二個請求。如何在soapUI中獲取webservice響應的值?

我可以使用${FirstStep#Response}來參考整個第一個響應。 但如何繼續?

假設答覆如下,我想提取標籤Key的價值:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <LoginResponse xmlns="http://schemas/WebServices"> 
     <Key>asdasdasd</Key> 
     </LoginResponse> 
    </s:Body> 
</s:Envelope> 

回答

1

您可以使用屬性擴展,像這樣:

${FirstStep#Response#//*:Key} 

或許必須通過讀documentation

2

有2方式:
1.使用上下文引用

e.g `context.expand('${RestTestStep#Response//xpathToDataNeeded}')` 
  • 可以得到整個響應,並使用XmlSlurper解析它。
  • def responseXml = testRunner.testCase.testSteps["StepName"].testRequest.response.getResponseContent(); 
    def xmlSlurperObj = new XmlSlurper().parseText(responseXml); 
    def xmlSlurperObj= new XmlSlurper().parseText(xml).declareNamespace(s:"http://schemas.xmlsoap.org/soap/envelope/"); 
    log.info xmlSlurperObj.Body.LoginResponse.Key.text(); 
    

    很好的鏈接瞭解XmlSlurper

    相關問題