2017-02-27 53 views
0

我使用的soapUI免費版和想添加兩個斷言加入斷言從結構

  • 首先斷言來檢查鍵總是存在於響應身體消息
  • 驗證值是對每個正確驗證關鍵鍵值對

例如:

{ 
     "data": "", 
     "success": "" 
     "statuscode": "" 
} 

可以任何人都可以指出我們如何使用soapUI免費版本實現這一目標。是groovy腳本只能達到這個目標嗎?

+0

這是整個迴應?或者只是響應的一部分? – Rao

回答

0

您可以使用Script Assertion作爲測試用例中的請求步驟,以實現您提到的斷言。

舉例來說,如果你把你提到的示例數據:

腳本斷言

//Below is the key value pair map that you are expecting from response 
//So define according to the expaction. Now just showing with example 
//values for demonstration 
def expectedMap = [data :'', success :'', statuscode :''] 

def response = """{ 
    "data": "", 
    "success": "" 
    "statuscode": "" 
}""" 

def json = new groovy.json.JsonSlurper().parseText(response) 
//check if actual response's keys and values are matched with expected map 
//Both of your questions are fulfilled by this 
assert expectedMap == json, 'Both are not matching' 

您可以快速地嘗試相同的在線Demo

輸出:
enter image description here

如果您想要處理動態響應(與上述固定響應不同),則可以使用下面的腳本代替上述腳本。

def expectedMap = [data :'', success :'', statuscode :''] 

assert context.response, 'Response received is either empty or null' 

def json = new groovy.json.JsonSlurper().parseText(context.response) 

assert expectedMap == json, 'Actual response is not matching with expected data'