Postman Tutorial Part 15 – Adding Automation Test Scripts In Postman
Hello Folks,
When we hit any API, we get some response along with status code, response time, headers etc. As of now we have verified it manually. Will it not be good if these assertion which we do manually should be auto performed once request is hit? A kind of automation testing of API.
Consider an example:-
Suppose you have a POST API to create a user. We need to hit this API with request body and it returns response which is generally details of newly registered user. It’s our responsibility to verify that whatever details we provided for user creation, same details are coming in response with extra properties like user id etc ( depends on API development). We should also verify the status code and message returned by APIs to cover more scenarios. In fact rigorous testing of API will drastically reduce number of probable bugs while during integration testing or system testing or front end testing.
It will be great if all discussed above could be achieved using automation testing of APIs. We can achieve the same using “tests” in Postman. All these tests will be run once request is hit and response is present.
Postman provides to write and run “Tests” for each request. It uses Javascript language. You should be aware of basic Javascripts. In face Postman makes it easier to add tests (By providing code snippets) to your request which we will see in this post.
In this post, we will going to practise using another set of APIs from Restful-Booker.
Above website provide a POST API to generate authentication token. Details are as below:
URI– https://restful-booker.herokuapp.com/auth
Request Body: –
{ “username” : “admin”, “password” : “password123”
}