Automate API tests with Postman

Payal Gaur
3 min readOct 15, 2020

--

Glad to have you back!!
Hope the previous blog was helpful in learning API Testing with Postman. Let’s explore postman assertions and learn running the tests using Collection Runner and Newman and make API testing more fun and interesting.

Assertion is the code used to analyze the value/response received from the server. It validates in Boolean expression(true/false). Assertion helps us to test that if the actual result is equal to the expected result. If both are not the same then the test result points to failure.

In postman, we have an easy way to assert our test cases, i.e. Snippets. It is the set of predefined codes that have unique functions available in the Postman app.

How to assert a test?

  1. Create a Get Request (we can use https://reqres.in/api/users?page=2 )
  2. Click on the ‘Test’ tab.
  3. Select any assertion block from the available snippet.

4. Hit the Send button.

5. Observe the test result.

The test result is PASS because the actual Result is equal to the expected Result

Running your Test Collection!

*Collection Runner

The collection runner is used to run all the requests in the postman app locally. It generates a report so that you can compare the performance of the test scenarios.
To run a collection, click on the chevron (>) next to the collection’s name. Select the blue Run button to open the Collection Runner in a new window.

Click Run (collection name) to execute it. Postman will display your request executions and test results in realtime.

Run Results

*Newman

Newman is a Command-line interface tool that allows us to run postman collection directly from the command line and build them into the development pipeline, responding to test outcomes to maintain your API performance. Newman is built on Node.js.

Getting Started:
1. Install Node.js. Now check the version of node and npm(node package manager) in the command prompt.

2. Install Newman from npm globally on your system.
$ npm install -g newman

3. Make a folder in your system and export collections to that folder.
Say file name- myCollection.json
Give a command: newman run <collection name> OR newman run <collection link>

You can see, the success and failure in the end report.

Test Result using newman

To practice APIs automation using Collection Runner and Newman you can use the demo APIs using the link.

Thank you for reading.
Happy Testing!

--

--