如何在邮递员测试中检查responseBody是否不包含字符串



要检查responseBody中的字符串,我们按以下进行搜索

tests["Body matches string"] = responseBody.has("string_you_want_to_search");

如何在邮递员测试中检查responseBody是否不包含字符串?

最"自然"和可读的语法如下,使用"流畅"风格的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;

最新更新