As a developer or tester I am sure you get encountered by a name called Postman. This is a super useful tool for testers to test their APIs and looks at the response get back from server. But I see a lot of people just using it as a manual testing tool. It appears to be like one but its much more powerful than that. Recently I got chance to explore Postman in bit detail and so I decided to do a multi part posts on that to introduce yourselves with our very useful friend "Postman" ;) You can find all parts as mentioned below, this is part 1.
Postman's most powerful features is its ability to run automated tests on API requests, which can be achieved using its Collection Runner. First most important segment of postman for this purpose is its Tests Tab. When you select the Tests tab you will see a console is available for writing test cases for your API calls. Your starters postman has provided set of pre written tests on right side in test tab as shown below in screenshot.
When open Postman, you should see the 'Tests' section in the request editor area.
To the right of the test editor, there is a list of snippets. You can click on any snippet title and the corresponding code snippet will be appended to the test editor.
Writing a simple test
For our first test, we'll send a GET request to http://echo.getpostman.com/get to find out the status of the API. We'll check if the status code is 200, and if the Content-Type header is "application/json". Follow the steps below:
- Set the URL to http://echo.getpostman.com/get
- Scroll down in the snippets editor and click on the "Status code: Code is 200" and "Content-Type header check" snippets
- This will add two lines in your Tests tab ( which are our tests that we need to verify against the response of API as shown in following snapshot.
Now lets press send button , we will get response as well as status of those two tests.
Next lets have a look on how we can automate all our test inside a collection and get result on press of a button.
Save your api calls in a collection. Click Runner button in Postman header as shown below :
This will open a new window shown below COLLECTION RUNNER:
Here you can see your collections list down under Type of filter drop-down. Once you select the collection and press Start Test button all tests inside this collection will be executed and once done you will be shown Results.
This is how postman is ready to help every developer to create/manage and evaluate API tests on just a single click.