0% found this document useful (0 votes)
7 views3 pages

API Testing Crash Course

This document provides a crash course on API testing, covering how to connect to a server and perform various response validations including status codes, headers, and response body assertions using JavaScript and the Chai Assertion Library. It includes examples of normal and arrow functions for testing status codes and headers. Additionally, it discusses how to get and set variables within scripts for enhanced testing capabilities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

API Testing Crash Course

This document provides a crash course on API testing, covering how to connect to a server and perform various response validations including status codes, headers, and response body assertions using JavaScript and the Chai Assertion Library. It includes examples of normal and arrow functions for testing status codes and headers. Additionally, it discusses how to get and set variables within scripts for enhanced testing capabilities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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:

You might also like