Testing With Postman: Checking Schema

Search for a command to run...

No comments yet. Be the first to comment.
In this series I will cover testing with postman and using it for automation.
Next is to setup a DevOps job you can go here to learn how to do that. For this section we will focus on the Execute shell and newman. With this I suggest going through Postman's official documentation found here. This takes your postman game and ups...
I have spent the last few weeks adding AI agents to my Playwright framework. Specifically Playwright's planner, generator, and healer, running locally through Claude Code. The Playwright agents explor

I decided to do a dump or a one stop shop for learning postman. You can go through my other post or just read this one. Testing Basics So to get started with postman you will need your API url and whether it is a GET, POST, PUT, DELETE or various oth...

Next is to setup a DevOps job you can go here to learn how to do that. For this section we will focus on the Execute shell and newman. With this I suggest going through Postman's official documentation found here. This takes your postman game and ups...

Another javascript library built into Postman is Lodash. #Looping Arrays with Lodash Sometimes you will want to iterate through an array. Maybe your response itself is an array. Luckily there is an easy for loop that can be used. This is use for wher...

Schema is something you need to test to make sure when they need a string that it is indeed a string. If you google postman and schema checking you will also find a cool tool called tv4. Do not use this as it is out dated and no longer supported. Please just create a test like below. Also create the jsonData inside the test so it bombs out a single test and not the whole collection when running.
pm.test("Has correct schema", function() {
let jsonData = pm.response.json()
pm.expect(jsonData.str).to.be.a("string", "str not a string and instead is " + jsonData.str);
pm.expect(jsonData.numArray[0]).to.be.a("number", "numArray[0] not a number and instead is " + jsonData.numArray[0]);
pm.expect(jsonData.numArray[1]).to.be.a("integer", "numArray[1] not a integer and instead is " + jsonData.numArray[1]);
pm.expect(jsonData.bool).to.be.a("boolean", "bool not a boolean and instead is " + jsonData.bool);
});
You can also output to the console if you would like something added to the log. Below are the different ways you can log to the console.
console.log(); outputs log messages to console console.info(); outputs information messages to console console.warn(); outputs warning messages to console console.error(); outputs error messages to console
An example is if you are calling a string object instead of a string. There is no or in Chai so you will need to use the below code.
pm.expect(jsonData.stringObject).to.be.to.satisfy(function(s){
return s === null || typeof s == 'string'
}, "stringObject is not a string or null")
Postman Quick Reference Guide Chai Assertion Library Regex Cheat Sheet Postman: The Complete Guide on Udemy