For programmers, testers and tech geeks

Postman test automation Part 1

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.

http://www.techintalk.com/post/2017/06/14/postman-test-automation-part-1

http://www.techintalk.com/post/2017/06/15/postman-test-automation-part-2

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.

Tests Tab

When open Postman, you should see the 'Tests' section in the request editor area.

 Tests tab in postman

 

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.

Postman test section

Writing a simple test

Let's now see how can we write a basic test using postman. Postman tests are written in Javascript. Postman renders the results in the "Tests" tab as well as in the Collection runner.

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:

  1. Set the URL to http://echo.getpostman.com/get
  2. Scroll down in the snippets editor and click on the "Status code: Code is 200" and "Content-Type header check" snippets
  3. 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.  Writing tests

Now lets press send button , we will get response as well as status of those two tests.

Postman run first test.

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 :

 Postman running collections

This will open a new window shown below COLLECTION RUNNER:

Postman Runner result for a collection

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.

 Postman runner results

This is how postman is ready to help every developer to create/manage and evaluate API tests on just a single click.

References :

http://blog.getpostman.com/2014/03/07/writing-automated-tests-for-apis-using-postman/