Postman: How to check whether the field is returning null in the Postman automation
66,423
Solution 1
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);
)};
Solution 2
Did you try
pm.expect(response.your_field).to.eql(null);
?
Solution 3
If you are checking the Id of the first item returned in a list, you could use not.equal(null)
:
pm.expect(pm.response.json().value[0].Id).not.equal(null);
Note that the word "equal" is fully spelled out, although the shortened "eql" does work.
Solution 4
Postman doesn't reference non-existent paths as null, but as undefined.
pm.expect(JsonResponse.FAKE.PATH).not.eql(undefined);
This test should fail, as this fake json path is actually undefined.
Solution 5
try this one:
pm.test("your-value is not null", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.your_value).not.eql(null);
});
Author by
Tester77
Updated on October 15, 2021Comments
-
Tester77 over 2 years
I have tried with
!== null
, but it is returning PASS even when the field is returning0
or empty string.