Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if responseBody does not contain string in postman tests

Tags:

postman

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 ?

like image 608
Kamal Avatar asked Mar 31 '16 16:03

Kamal


Video Answer


2 Answers

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.

like image 92
Mathieu VIALES Avatar answered Oct 20 '22 02:10

Mathieu VIALES


You can try this:

tests["Body does not have supplied string"] = !(responseBody.has("string_you_want_to_search"));
like image 10
Dinesh Kumar Avatar answered Oct 20 '22 00:10

Dinesh Kumar