【发布时间】:2020-11-18 11:42:42
【问题描述】:
我需要获取当前确切的集合变量值。
在邮递员请求的预请求脚本中,我正在设置 2 个集合变量,如下所示
pm.collectionVariables.set("firstCollectionVariable", "string_{{$guid}}");
pm.collectionVariables.set("secondCollectionVariable", "second_variable_{{firstCollectionVariable}}");
然后我在 post 请求正文中使用这 2 个集合变量来设置特定数据,如下所示
{
"firstKey": {{firstCollectionVariable}},
"secondKey" : {{secondCollectionVariable}},
}
firstKey 和 secondKey 按预期设置
firstKey => "string_c6631d2c-2427-4903-b604-8120662a5e0e"
secondKey => "second_variable_string_c6631d2c-2427-4903-b604-8120662a5e0e"
问题是当我尝试使用检查响应时
pm.expect(pm.response.secondKey).to.eql(pm.collectionVariables.get("secondCollectionVariable"));
我得到了断言错误
AssertionError:预期 'second_variable_string_c6631d2c-2427-4903-b604-8120662a5e0e' 到 深度相等'second_variable_{{firstCollectionVariable}}'
如何获取集合变量的当前准确值?
【问题讨论】:
-
这能回答你的问题吗? Accessing Collection Variables in Postman
标签: postman postman-native-app