【问题标题】:How to get the value of key from the body of Json response using Postman Test?如何使用 Postman Test 从 Json 响应的正文中获取键的值?
【发布时间】:2022-03-11 02:18:47
【问题描述】:

嗨团队我有响应Json,其身体如下

{
\"host\": \"telemarket-backend.val.io\",
\"ssl-client-verify\": \"NONE\",
\"x-request-id\": \"916633224df75cb3cd728631879612181761\",
}

当我在邮递员中为上述机构编写测试时,如上所述

const responseJson=pm.response.json();
pm.test(\"Validate the SSL \",function(){
pm.expect(responseJson.ssl-client-verify).to.eql(\"None\");
});

上面一个没有按预期工作,而下面一个按预期工作

pm.test(\"Validate the host  \",function(){
pm.expect(responseJson.host).to.eql(\"telemarket-backend.val.io\");
});

你能告诉我它为什么不起作用的原因以及可以在邮递员上工作的修复解决方案吗

  • 即使responseJson.ssl-client-verify 是合法表达,None 是否等于 NONE?
  • 我发现的正确解决方案是 pm.expect(responseJson[ssl-client-verify]).to.eql(\"NONE\");

标签: postman-collection-runner postman-testcase


【解决方案1】:

我发现的正确解决方案是 pm.expect(responseJson[ssl-client-verify]).to.eql("NONE");

【讨论】:

  • 问题是,这一切都出现在我给你的评论中。好像都没读过?而且,你不是解释任何事物;你只是在向我们抛出“正确”的答案,没有任何解释。那没用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-18
  • 2017-08-24
  • 1970-01-01
  • 1970-01-01
  • 2022-09-26
  • 1970-01-01
  • 2021-08-12
相关资源
最近更新 更多