我正在使用Postman做一些回归测试,我在Pre-request Script选项卡上有以下函数:
postman.setGlobalVariable("verifyResponseChildValueMatchesExact", (children, key, value) => {
pm.test(`A node with these parents '${children}' in the response should contain this key / value pair '${key}: ${value}'`, function() {
const targetJson = eval(globals.getResponseChild)(children);
if (!targetJson) throw new EvalError(`Node with parents '${children}' does not exist.`);
pm.expect(Object.keys(targetJson)).to.include(key);
pm.expect(targetJson[key]).to.eql(value);
});
});
字符串
我称之为使用:
eval.globals.verifyResponseChildValueMatchesExact(["my_key"], "my_value", my_number)
型
待验证的响应为:
{
"data": {
"my_key": 42
}
}
型
我需要的是一个函数,它遵循该结构,但能够验证数组中任何位置的键和值
{
"data": [
{
"my_key": 42
}
]
}
型
如果可能的话(在同一功能中)
{
"data": [
{
"my_key": 42,
"my_key2": {
"my_key3": "value"
}
}
]
}
型
例如:data,在位置0有一个名为“my_key”的孩子,它的值是42。这就是我需要验证的
1条答案
按热度按时间aiqt4smr1#
您将需要一个函数来递归地检查需求是否为真。
字符串