我使用Gatling工具加载测试我的服务。 我有来自我的服务器的响应(仅作为示例):
{
"result: {
"288249": {
"allowEdit": 1,
"cells": [
{
"rollupId": "288249",
"description": "Gatling description: 93"
},
{
"rollupId": "288249",
"description": "Gatling description: 83"
}
]
}
}
}
我需要的是循环思考所有$ .result.288249.cells [*]。描述字段并验证是否有一个值,它等于我在其中一个会话对象中的值。 它应该类似于以下伪代码:
.check(
jsonPath("$.result.*.cells[*].description").contains("${mySessionValue})
)
是否有方法,我可以用类似的方式使用?
提前致谢!
答案 0 :(得分:4)
我想,我找到了解决方案
.check(
jsonPath("$.result.*.cells[?(@.description == '${mySessionValue}')]")
.find
.exists
)
这应该做的工作。
答案 1 :(得分:-1)
您可以按如下方式循环
$.each($.result, function(index,obj){
$.each(obj['cells'], function(innerInd, innerObj){
if( ${mySessionValue} == innerObj['description'] )
{
console.log('Found')
return
}
})
})