【问题标题】:How to compare response with global variable in postman如何在邮递员中将响应与全局变量进行比较
【发布时间】:2018-02-28 01:35:24
【问题描述】:

我在邮递员中定义了一个全局变量,我正在发出一个帖子请求。我想知道响应是否包含我在全局变量中设置的值。

pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include({{sample_message}});
});

sample_message是全局变量

如何比较??提前致谢

【问题讨论】:

    标签: javascript postman


    【解决方案1】:

    经过大量网络研究,我得到了解决方案

    pm.test("Body matches string", function () {
      pm.expect(jsonData.data.message_content).to.eql(pm.environment.get("sample_message"));
    });
    

    pm.environment.get("sample_message") 将获取全局变量的值

    来源:Writing tests in Postman

    【讨论】:

      【解决方案2】:

      Postman 无法解决测试选项卡中的 {{}} 变量。

      将 {{sample_message}} 替换为 postman.getGlobalVariable("sample_message")

      【讨论】:

        猜你喜欢
        • 2020-05-15
        • 1970-01-01
        • 1970-01-01
        • 2013-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-18
        • 2016-07-18
        相关资源
        最近更新 更多