Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman: How to check whether the field is returning null in the Postman automation

I have tried with !== null, but it is returning PASS even when the field is returning 0 or empty string.

like image 324
Tester77 Avatar asked Mar 24 '17 06:03

Tester77


People also ask

How do you check an empty postman response?

Empty response — JSONError: No data, empty input at 1:1test("Status code is 204", () => { pm. response.to.have. status(204);}); You can also check that the response is indeed empty (if this is the expected behaviour).

How do you validate response value in Postman?

#1) Firstly, we try to store the schema for the JSON in a local variable. #2) We now store JSON from the actual request execution through pm object. #3) Now, we add an assertion in pm. expect() block, and use the TinyValidator library to validate JSON response against the given schema.

How do you assert a postman?

In Postman, we can write the assertion in many ways. One of the simplest ways is the snippets, which are nothing but a block of codes that have some unique functions inside it and are available in the postman app. Users can easily access the snippets and can get the code inside the tests editor and run the test.


2 Answers

This works as of Mar-2019:

pm.test("To Check if Value is Null", function() {
var jsonData = pm.response.json();
pm.expect(jsonData.<yourfield>).not.eq(undefined);
)};
like image 98
Shiraz Avatar answered Sep 21 '22 05:09

Shiraz


Did you try

pm.expect(response.your_field).to.eql(null);

?

like image 35
Old Panda Avatar answered Sep 19 '22 05:09

Old Panda