有没有一种方法可以验证请求中给定的值是否存在于响应中



我在请求中给定了一个参数(例如:date=2020-03-12(。我需要通过不直接在脚本中给定值(2020-03-12(来验证是否存在相同的日期作为响应。因为这个日期是动态的,而且会经常更改。因此,我需要单独使用日期变量来检查请求中给定的日期值是否存在于响应中。我希望问题是明确的

测试时,Request和Response对象都可用,因此您可以检查是否存在值。假设json有效载荷:

pm.test('Response contains data from Request', function () {
const RequestJSON = pm.request.json();
const ResponseJSON = pm.response.json();
pm.expect(RequestJSON.Text).to.equal('Request Text in Text field');
pm.expect(ResponseJSON.Text).to.equal('Request Text in Text field');
// Or if you do not care about the field data
pm.expect(RequestJSON.Text).to.equal(ResponseJSON.Text);
});

最新更新