How to Perform POST Request in Postman with Test Validation?
Open this link https://www.postman.com/downloads/ and download the Postman.
After completing the download install the software in the system. In this article, we are going to POST the data using the URL “https://reqres.in/api/login” and write the Test validation script to run the tests for API.
In the POST method, we are passing some data to the API. In this example we are sending the email and password for login API, if this is valid we will receive a token for login.
Steps for creating the POST method:
- Create a new workbook
- Create a Collection in that workbook.
- After creating the collection, now create a POST method into it.
- Add the URL.
- Move to the Body tab and select the option raw.
- After that, choose JSON from the dropdown.
Now, we have to enter the valid username and password in the JSON format in the body.
If the mail and password are valid we get the token as a response and status code as 200.
otherwise, we will get an error.
Adding Test validation
- Now navigate to the tests tab.
- After that an example for writing a test to this POST request, we have to check the response code is 200, and check the response body has the “token” present in it.
tests[“Checking response code”]=responseCode.code==200;
tests[“validating token presence”]=responseBody.has(“token”);
After the tests are written save the collection and now run it by clicking the send button.
Please Login to comment...