API Test use Postman and create Newman Report
What is API ?
API stands for Application Programming Interface, and it is a software mediator that allows two programs to communicate with one another. An API is used every time you use an app like Facebook, send an instant message, or check the weather on your phone.
Postman
Postman is an API testing program. It is an HTTP client that tests HTTP requests by using a graphical user interface to acquire various sorts of answers that must then be verified.
Method
Postman provides several endpoint interaction techniques. The following are some of the most often used, along with their functions:
GET: Get information
POST: Include information
PUT: Insert new data.
PATCH: Update certain information
DELETE: To delete data.
Response
The response code received by the API is shown by Postman. Hover over the answer code to see a brief summary of what it signifies.
- 100 Series > Temporal reactions, such as ‘102 Processing.’
- 200 Series > Responses when the client accepts the request and the server correctly executes it, such as ‘200 Ok’.
- 300 Series > URL redirection responses, such as ‘301 Moved Permanently.’
- 400 Series > Client error replies, such as ‘400 Bad Request.’
- 500 Series > Responses to server errors, such as ‘500 Internal Server Error.’
Read Documentation Example
- Rajaongkir API
RajaOngkir provides a RESTful API (Application Programming Interface) that you can use to create various applications that require data transfer costs. The cost of sending data is taken directly from the website of each courier to maintain data accuracy.
Step 1 -> Login / Signup and Generate API Key
Step 2 -> Read Documentation
Step 3 -> Test API at Postman
After see the required parameter such as API Key then after create request at Postman, rename request to List Kota, change method to Get, input URL target, add required parameter (API Key) and click send
When the response is 200 Ok then the process is PASS
2. The OMDb API
The OMDb API is a RESTful web service for retrieving movie information; all content and pictures on the site are supplied and maintained by users.
Step 1 -> Read Documentation & Sign In to Get API Key
Step 2 -> Find paramater value, Due to we can check IMDB ID thus I want to check Pengabdi Setan 2 using this API
Step 3 -> Test API with Postman
- Open Postman
- Create collection
- Add request and change name the request
- Change Method to GET
- Fill Url http://www.omdbapi.com/
- Fill Api Key Value at Paramater
- Fill I value using Pengabdi Setan 2
- Click Send
- See the respon
Create Report API Test with Newman
I will create report the API Test from documentation
https://market-final-project.herokuapp.com/api-docs/#/ from apps https://deployed-five.vercel.app/
Step 1
- Open API Documentation
- Learn what is request that you will test
This picture below give example of documentation and what are the parameters that must inserted to the Postman
Step 2
- Open Postman
- Create collection, rename it with your project name
- Add new request and rename it with your request for instance post_auth_register usually it will similar with API Documentation
- Match the method with the documentation (GET/POST/DELETE/PUT)
- Insert Url target
- Input parameter
- And click Send
Step 3
- Ensure the response
Step 4
- Create test documentation
- You can see documentation reference at https://learning.postman.com/docs/writing-scripts/script-references/test-examples/
- For example :
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
Newman Report
- Save all your requests at Postman
- Export the collection into .json file
- Open your text editor
- Open your terminal
- Install Newman
$ npm install -g newman-reporter-html
- Run the newman
newman run <filename>.json -r htmlextra
- Then your folder newman report can be seen at your project folder
- Open the newman file at your browser
References
https://learning.postman.com/docs/sending-requests/responses/