To check for a string in the responseBody, we do the search as follows
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
How to check if responseBody does not contain string in postman tests ?
The most "natural" and readable syntax is as follow, using a "fluent" style API
pm.test("Body matches string", function ()
{
pm.expect(pm.response.text()).to.not.include("string_you_want_to_search");
});
As Stefan Iancu pointed out, this only seems to work in the standalone version of Postman.
You can try this:
tests["Body does not have supplied string"] = !(responseBody.has("string_you_want_to_search"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With