【问题标题】:Postman assertion twice the identically variable邮递员断言两次相同的变量
【发布时间】:2020-09-15 14:40:16
【问题描述】:

我正在尝试断言响应正文。我曾经的第一个断言是有效的。关键是responsbody中有多个同名变量。我还需要保留环境变量。

我试过了,但它不起作用:

pm.test("response is ok", function () {
pm.response.to.have.status(200);
});

const body = pm.response.json();
pm.test("VoyageId sent", function() {
pm.expect(body).to.have.property("key", (pm.environment.get("voyageId")));
});

pm.test("VisitId sent", function() {
pm.expect(body).to.have.property("key", (pm.environment.get("visitId")));
});    

Printscreen Postman

【问题讨论】:

    标签: variables postman assertion


    【解决方案1】:

    这应该可以解决问题:

    const resBody = pm.response.json();
    
    pm.test("Rotatie ...", function () {
        pm.expect(resBody.key).to.eql(pm.environment.get("voyageId"));
    });
    
    pm.test("Visist ...", function () {
        pm.expect(resBody.calls[0].key).to.eql(pm.environment.get("visitId"));
    });
    

    【讨论】:

    • 感谢您的回复,但需要变量中的它们。
    • @EEO27 太好了!如果您能接受并支持我的回答,将不胜感激。谢谢!
    猜你喜欢
    • 2019-12-21
    • 1970-01-01
    • 2021-08-14
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 2021-07-27
    相关资源
    最近更新 更多