[英]groovy script SOAP UI json response parse
How to parse json
response using groovy script. 如何使用Groovy脚本解析json
响应。
I am using SOAP UI and have json response as below- 我正在使用SOAP UI,并具有以下json响应-
{
"resource": {
"name":"aaaaaaaaaaa",
"emailid":"bbbbbbbbb"
}
}
Can anyone please share sample code to parse json object and post that some basic assertions check. 任何人都可以共享示例代码来解析json对象并发布一些基本断言检查。 Thanks 谢谢
Add a Script Assertion
for the rest request test step with below script. 使用下面的脚本为其余请求测试步骤添加一个Script Assertion
。
JsonSlurper
can be used to parse the response. JsonSlurper
可用于解析响应。
//Check if the response is not empty
assert context.response, 'Response is empty or null'
//Define expected data
def expectedData = [name: 'aaaaaaaaaaa', emailid: 'bbbbbbbbb']
def json = new groovy.json.JsonSlurper().parseText(context.response)
//Checks all elements of resource one by one and compare with expectedData
json.resource.each {k, v -> assert v == expectedData."$k" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.