【发布时间】:2016-07-20 06:06:37
【问题描述】:
要检查 responseBody 中的字符串,我们按如下方式进行搜索
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
如何在 postman 测试中检查 responseBody 是否包含字符串?
【问题讨论】:
标签: postman
要检查 responseBody 中的字符串,我们按如下方式进行搜索
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
如何在 postman 测试中检查 responseBody 是否包含字符串?
【问题讨论】:
标签: postman
最“自然”和可读的语法如下,使用“流利”风格的API
pm.test("Body matches string", function ()
{
pm.expect(pm.response.text()).to.not.include("string_you_want_to_search");
});
正如 Stefan Iancu 指出的,这似乎只适用于 Postman 的独立版本。
【讨论】:
你可以试试这个:
tests["Body does not have supplied string"] = !(responseBody.has("string_you_want_to_search"));
【讨论】:
var data = JSON.parse(responseBody);
tests["Body does not contain string_you_want_to_search"] = data.search("string_you_want_to_search") < 0;
【讨论】: