API Testing Crash Course
Connect to server :
C:\API Testing\Json files> json-server [Link]
Response validations:
Status code
Headers
Cookies
Response time
Response body
Assertion - validation
pm - library
functions
javascript
Normal functions
Arrow functions
Chai Assertion Library
pm. test ("Test Name", function ()
{
// assertion
}
);
pm. test ("Test Name", () =>
{
// assertion;
}
);
Testing status codesTest for the response status code:
pm. test ("Status code is 200", () =>
{
pm. response. [Link] (200);
});
If you want to test for the status code being one of a set, include
them all in anarray and use one of
pm. test ("Successful POST request", () => {
[Link] (pm. response. code) . [Link] ([201, 202]);
});
Check the status code text:
pm. test ("Status code name has string", () =>{
[Link] ("Created") ;
});
Testing headers
Check that a response header is present:
pm. test ("Content-Type header is present", () => {
pm. response. to. have. header ("Content-Type") ;
});
Test for a response header having a particular value:
pm. test ("Content-Type header is application/json", () => {
[Link]([Link]("Content-
Type')).[Link]('application/json; charset=utf-8') ;
});
Add and Refer Varaibles:
Get & Set variables with scripts: