我需要获取当前的确切集合变量值。
在邮递员请求的预请求脚本中,我按如下所示设置 2个集合变量
pm.collectionVariables.set("firstCollectionVariable", "string_{{$guid}}");
pm.collectionVariables.set("secondCollectionVariable", "second_variable_{{firstCollectionVariable}}");
然后我在后请求正文中使用这两个集合变量来设置特定数据,如下所示
{
"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}}”
如何获取集合变量的当前精确值?
答案 0 :(得分:1)
也许使用to.be.deep
可以解决您的问题,请尝试以下操作:
pm.expect(pm.response.secondKey).to.be.deep.equals(pm.collectionVariables.get("secondCollectionVariable"));
或
pm.expect(pm.response.secondKey).to.be.deep.equal(pm.collectionVariables.get("secondCollectionVariable"));
另一个不错的选择就是使用单引号将您的collectionVariable设为'secondCollectionVariable'
我希望这对您有用,最好的问候!
答案 1 :(得分:0)
将变量转换为字符串也可以解决您的问题。