gpt4 book ai didi

web-services - 如何使用 REST Assured 验证嵌套响应?

转载 作者:行者123 更新时间:2023-12-04 05:15:21 24 4
gpt4 key购买 nike

需要帮助使用 REST Assured 库从下面的响应中验证特定的 JSON 参数。

我尝试了一些选项来验证其他类似的参数,如下所示,但没有用。

.then().body("value.value.value.name", hasItems("balanceResultCode")).body("value.value.value.value", hasItems("0"));

如果我想从下面的响应中验证“resultCode”和“subscriberIdType”,那么我该怎么做?
[  
{
"name":"Id",
"value":"11"
},
{
"name":"version",
"value":null
},
{
"name":"header",
"value":[
{
"name":"mVersion",
"value":"1"
},
{
"name":"Name",
"value":"BalQ"
},
{
"name":"appID",
"value":"90091"
},
{
"name":"requestUid",
"value":"REST_REQUQEST_1"
},
{
"name":"sessionId",
"value":"REST_SESSION_1"
},
{
"name":"requestType",
"value":"SomeRequestType"
},
{
"name":"requestNumber",
"value":"REQ_111"
},
{
"name":"requestDuplicate",
"value":"1"
},
{
"name":"serviceProvider",
"value":1
},
{
"name":"username",
"value":"user"
},
{
"name":"password",
"value":"pass"
},
{
"name":"resultCode",
"value":100
}
]
},
{
"name":"content",
"value":[
{
"name":"subscriberAddressing",
"value":[
{
"name":"subscriber",
"value":[
{
"name":"subscriberIdType",
"value":200
},
{
"name":"subscriberIdValue",
"value":"1234567890"
}
]
}
]
}
]
}

]

最佳答案

这是一种方式:

then().
body("find { it.name == 'header' }.value.find { it.name == 'resultCode' }.value", is(100)).
body("find { it.name == 'content' }.value.find { it.name == 'subscriberAddressing' }.value.find { it.name == 'subscriber' }.value.find { it.name == 'subscriberIdType'}.value", is(200));

您可以阅读 Groovy 集合和 GPath 以了解更多信息。

关于web-services - 如何使用 REST Assured 验证嵌套响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29585604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com