【问题标题】:How to get assertion result in variable using Postman Test如何使用 Postman 测试在变量中获取断言结果
【发布时间】:2020-12-18 10:25:05
【问题描述】:

我无法得到断言的结果。下面提到的是例子

//代码

pm.test(“Status code is 200”, function() {
pm.response.to.have.status(2001);
});

我想在变量中获取结果,以便可以在其他代码中使用此断言值(如附件电子邮件中所述)。

例如:VARIABLE

中保存“状态码为200 | AssertionError:预期响应为状态码2001但得到401”的值

See image

【问题讨论】:

    标签: postman assertion getvalue


    【解决方案1】:
    let error;
    pm.test("Status code is 200", function () {
        try {
            pm.response.to.have.status(2001);
        }
        catch (err) {
            error = err
            pm.response.to.have.status(2001);
        }
    
    });
    
    
    
    console.log(error)
    

    只需使用 try 和 catch,我不知道为什么这是一个用例。你可以把它变成变量

     pm.environment.set("error",error)
    

    【讨论】:

      猜你喜欢
      • 2022-11-23
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2016-11-25
      相关资源
      最近更新 更多