【问题标题】:Postman test case insetitivePostman 测试用例 insetitive
【发布时间】:2020-10-05 17:24:26
【问题描述】:

我在 Postman 中有一个测试用例,如下所示:

pm.test("Last Name contains Bob", () => {
    const responseJson = pm.response.json();
    pm.response.to.have.status(200);
    pm.response.json().result.length >= 1;
    pm.expect(responseJson.result[0].last_name).to.include.a("Bob");
});

但是对于 BOBBY 为 last_name 的结果会失败

我认为通过将a 添加到断言中,它将变得不区分大小写。

那么我做错了什么?

【问题讨论】:

  • Postman 使用 Chai 断言库,a 不是这样工作的。 chaijs.com/api/bdd/#method_a 你可以使用match 并使用正则表达式来区分大小写吗?
  • @DannyDainton Youp, match 使用适当的正则表达式。谢谢!
  • 可能值得添加您的解决方案并接受它作为答案,以便访问这里的人们也可以看到它。 ??????

标签: postman postman-collection-runner


【解决方案1】:

我的情况的解决方案是使用 match 和正则表达式

pm.test("Last Name contains Bob", () => {
    const responseJson = pm.response.json();
    pm.response.to.have.status(200);
    pm.response.json().result.length >= 1;
    pm.expect(responseJson.result[0].last_name).to.match(\Bob\gmi);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 2020-12-31
    • 2018-01-10
    • 2020-10-23
    • 2022-01-21
    相关资源
    最近更新 更多