In this tutorial, We are going to write some TESTCASES in the POSTMAN Chrome as a part of API Testing.
API Testing includes
1. JSON Schema Validation
2. Response Time Verification
3. Verification of the Keys defined in response by API
4. Values as Expected (Data driven Testing) in response
Learn about JSON Schema – http://jsonschema.net
Code –
URL – https://jsonplaceholder.typicode.com/posts/1
Test Code –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); tests["Response time is less than 200ms"] = responseTime < 500; tests["User ID is Present"] = responseBody.has("userId"); tests["ID is Present"] = responseBody.has("id"); tests["Title is Present"] = responseBody.has("title"); tests["API Bodyis Present"] = responseBody.has("body"); var jsonData = JSON.parse(responseBody); tests["User ID should be "+jsonData.userId] = jsonData.userId === 1; console.log("User ID I am getting from API is "+jsonData.userId); var schema = { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "userId": { "type": "integer" }, "id": { "type": "integer" }, "title": { "type": "string" }, "body": { "type": "string" } }, "required": [ "userId", "id", "title", "body" ] }; tests["Valid scehma"] = tv4.validate(jsonData, schema); console.log("Validation failed: ", tv4.error); |
Hello TechMode, do you have an email address or Skype contact?
Thanks for the post.
I was trying to use json schema.net but it does not seem to be generating the Json schema.
Please help.
Thanks,
Arvind
Hello Promode,
I am following your blog related to schema validation via postman but found that and trying to use in my own test
Command on line#38 tests[“Valid schema”] = tv4.validate(jsonData, schema); will pass for all the time even if you make changes to schema.
Please let me know if you have another way of validation schema.
I would suggest you to go through this link – http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/
Hello,
Nice Explanation. Im new to API testing, and I tried your examples.
I tried writing test cases following your video, just small doubt .
When I click on any snippet like – Response body:Contains String – I get this in the test case tab -pm.test(“Body matches string” , function () {
pm.expect(pm.response.text()).to.include(“userId”);
});
And I have seen on your screen as – tests[“Content-Type is present”] = postman.getResponseHeader(“Content-Type”);
Can you please explain me why I’m getting diferent . That would be helpful. Thanks
Its just new version difference. You can get the pre-made assertions now in postman 😄
how to test multiple API at a same time in postman like 100 API URL mention in json file or any other file then import in postman for testing.
Parallel execution is not possible in Postman as of now, You can try using Karate API or running multiple instances of newman(postman)
Hi Promode, thanks for reply. but i have one doubt. can we use collection runner or multiple instances of newman?? mean both gives same result or not?? if we try to test multiple API. I am new for API testing and also start using postman.
Yes, You can use the multiple instances of the Newman, You can get more tutorials about the API Testing here – https://www.youtube.com/c/itstechmode