How to use Postman for API test automation. Part I – First test
Postman becomes more and more popular tool for API so we decided to do a small series of posts on our experience and best practices on how to use this tool for API testing. This series will be useful for developers as well as for QAs. As you will get some new approaches that can be used in order to quickly write and validate you API.
In order to show how to use Postman you will have to download a postman application which is available for Mac OS, Windows x32, Windows x64, Linux x32, Linux x64 and as a Chrome plugin. To show you most basic functions of Postman we will use The Star Wars API this is a simple API that returns a data for all characters, planets and many more from Start Wars universe. So lets get started.
First of all install Postman application (links for each OS is above) and sign up or log in into application. You will see something like this when you are ready to use application :
So what do we have here? On a left hand side there is a column with all your saved collections(test sets). In a middle we have a dropdown that has a request type, URL and “Send” button. This is a part that we will work the most from now on. Also we have environment dropdown at the right top corner of application. But we will come back to environments later and now let’s run our first request using Postman.
Type in “https://swapi.co/api/planets” in to “Enter request URL” field and hit Send. You should see something like this in response :
As you can see a response status is 200 OK and response time is 1290 ms(1.29 sec) and we have 61 items in our collection (61 planets in Start Wars universe). After that we have a whole bunch of planets in a list called “results”. As we have successfully executed our first request. Now let’s try to write our first test and execute request again.
We will try to add two tests for response code in order to know that our request was successful. Another test we will add for response time < 2 sec in order to understand how fast request was processed by server. If it will be executed slower then for 2 seconds, our test will fail. In this case I use 2 seconds just for example it might be greater or lower number, but 7 seconds is usually a maximum time for request execution. So in order to add tests, go to “Tests” in request section of application and add this few lines :
tests["Status code is 200"] = responseCode.code === 200;
tests["Response time is less than 200ms"] = responseTime < 2000;
When this is done hit on Send button again and execute your first test. Result should look like this :
We will continue on more advanced tests and postman functions in a next part.
Thank you for attention
and hope it was useful
for someone out there!