【问题标题】:Error while executing Postman Test Script执行 Postman 测试脚本时出错
【发布时间】:2021-03-06 04:47:18
【问题描述】:

我正在编写 Postman 测试用例。我从以下测试用例中收到错误

pm.test("Response to have expected data", function () {
   pm.expect(documentIdArray).to.have.members(['5868', '4', '5874']);  
});

There was an error in evaluating the test script:  Error: expected [ '4837', '4', '5874' ] to have the same members as [ '5868', '4', '5874' ]

【问题讨论】:

  • documentIdArray 的值是多少,如何设置?您在这里遗漏了一半的信息。

标签: testing postman postman-testcase


【解决方案1】:

我认为您在 documentIdArray 中有字符串。你可以解析它:

pm.test("Response to have expected data", function () {
   pm.expect(JSON.parse(documentIdArray)).to.have.members(['5868', '4', '5874']);  
});

否则将数组字符串化并比较(推荐),因为终点实际上不是返回数组而是字符串它应该是一个错误

pm.test("Response to have expected data", function () {
   pm.expect(documentIdArray).to.be.equal(JSON.stringify(['5868', '4', '5874']));  
});

【讨论】:

    猜你喜欢
    • 2019-01-02
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多