【问题标题】:Is there a way to verify a value given in request is present in response or not in postman?有没有办法验证请求中给出的值是否存在于邮递员中?
【发布时间】:2020-11-02 08:48:57
【问题描述】:

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

【问题讨论】:

  • 展示你的尝试和错误

标签: javascript postman-testcase


【解决方案1】:

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);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-09
    • 2021-04-13
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 2021-01-14
    相关资源
    最近更新 更多