我使用soapui 5.3.0测试REST API。
我的请求返回json,如下所示:
[
{
"name": "John",
"online_status": "online"
},
{
"name": "Marry",
"online_status": "online"
}
]
我如何使用jsonpath Expresstion验证所有"在线_STATUS"都在线,而不是其他
您可以使用Script Assertion
进行相同的REST请求测试步骤。
您去这里:
assert context.response, 'Response is null or empty'
def json = new groovy.json.JsonSlurper().parseText(context.response)
//Get the online_status as Set; so unique value are stored
def result = json.collect{it.'online_status'} as Set
//It should be only one as expected
assert 1 == result.size()
//It should only have online
assert result == ['online'] as Set
如果您想快速尝试脚本,请检查 demo