Karate框架中Json数组的条件检查



想要在Karate框架中进行验证对于下面的Json,我想验证的是,

如果";isfilter_regex":0,则";消息类型":"#正则表达式^[A-Za-z0-9_.]-/*">
或者如果";isfilter_regex":1,则";消息类型":"字符串";(当isfilter_regex=1时,则msgtype必须是正则表达式(

在我的情况下,候选者数组中的候选者数量为180+我尝试了很多事情,但都失败了,有人能帮我吗?

{
"candidates":[
{
"candidate":{
"name":"Alex",
"category":[
{
"category_name":"APCMRQ",
"filters":[
{
"isfilter_regex":0,
"msgtype":"APCMRQ"
}
]
},
{
"category_name":"BIDBRQ",
"filters":[
{
"isfilter_regex":1,
"msgtype":"'(AMSCNQ(_[A-Za-z0-9]{1,3}){0,3})'"
}
]
}
]
}
}
]
}

我尝试了以下方法,该方法仅在指定idex时有效,但如果我想对整个数组进行此检查,该怎么办?,

* def msgRegexValue = response.candidates[150].candidate.category[0].filters[0].isfilter_regex
* def actualFilter = response.candidates[150].candidate.category[0].filters[0]
* def expectedFilter = actualFilter
* def withRegex =
"""
{
"isfilter_regex": 0,
"msgtype": '##regex ^[A-Za-z0-9_.]*-*/*'
}
"""
* def withoutRegex =
"""
{
"isfilter_regex": 1,
"msgtype": '##string'
}
"""
* def expected = msgRegexValue == 0 ? withRegex: withoutRegex
* match actualFilter == expected

最新更新