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

问题描述

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

解决方法

在测试时,请求和响应对象均可用,因此您可以检查是否存在值。假设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);
});