Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.
Hello everyone,
Is there any way for postman to check if a specified field contains one or more items below. For a sample response below:
Thanks @bpricilla will try it. Basically, if there’s anything inside “r”: {} it’ll pass the test.
It’s actually one of my first steps, soon I will have to check for specific numbers of items under r but for one I willjust have to verify if there’s anything under.
Hello
This test will check if given key contains R key and in next it will test if it contain at least on of the given keys
if(pm.response.to.be.success){
pm.test("respons has R key", function() {
pm.expect(pm.response.json()).to.have.property('r');
});
pm.test("R key is an object", function() {
pm.expect(pm.response.json().r).to.be.an('object').that.has.any.keys('UsedBy');
});
}
You can change .any.keys to .all.keys if you expect only this one key or list of them to appear.
More you can find in official docs