2017-02-27 73 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'