要检查responseBody中的字符串,我们按如下方式进行搜索
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
如何在postman测试中检查responseBody是否包含字符串?
答案 0 :(得分:20)
为了更流畅和可读的语法,您还可以使用以下
6
答案 1 :(得分:9)
你可以试试这个:
tests["Body does not have supplied string"] = !(responseBody.has("string_you_want_to_search"));
答案 2 :(得分:0)
这可能适合你,
tests["Body does not contain"] = responseBody !== "string_you_want_to_search";
答案 3 :(得分:0)
var data = JSON.parse(responseBody);
tests["Body does not contain string_you_want_to_search"] = data.search("string_you_want_to_search") < 0;