Automation & Documentation using Postman

4

What is Postman, and why use it?

Postman is an API Development Environment that helps people to build, test, document, monitor and publish documentation for their APIs.

Postman is used by 6 million developers and more than 200,000 companies to access 130 million APIs every month. API testing is likely to grow further in 2019 so knowing how to use Postman effectively will be a powerful asset.

Imgur & HarperDB published their API documentation using postman.

Here’s what you need to know about your Postman:

What is the goal?

Testing APIs is often slow, error-prone and annoying. Instead of manually checking an endpoint’s response, we can write integration tests with Postman to examine and validate the response. We also want to automate running these tests with our deployment process. One approach you can take is to have your integration tests run every time a developer checks in code to your repo.

Rapid feedback!

Why do we want to do this?

Automate your QA and Testing processes! While this is in the right direction, this doesn’t fool proof. This adds another layer of quality control but we need to ensure our tests are thorough and up to date.

The idea is to ensure existing functionality still works as expected when we add new features to our API. Having this process automated, will identify unexpected issues early in the development life cycle and will help the developers evaluate their code.

Let’s get familiar with the features which are commonly used

Newman 

Newman is Postman’s collection runner engine that sends API requests, receives the response and then runs your test against the response. It is extensible and so can be integrated into continuous integration servers and build systems.

Runner

Postman’s Collection Runner lets you run all the requests inside a collection locally in the Postman app. It also generates reports so that you can measure the performance of your tests.

Variables

Two main types of variables – global and environment. Global variables are for all Collections, whereas the environment variables are defined for a specific set of collections

Click on Manage Environment Setting & You can create a new environment

Click on Manage Environment Setting -> Click on Global Button
& You can create a new global variable

Scripts

Postman allows users to perform specific JavaScript coding to manipulate the data being sent along with the request. We can write these scripts in Tests section and pre-request section. We can set Global and Environment Variable dynamically as well.


postman.setGlobalVariable(“Token”, “xyzToken”);
postman.setEnvironmentVariable(“Username”, “myUserName”);
postman.getGlobalVariable(“Username”);

Console

Postman Console is analogous to a browser’s developer console, except that it’s tuned for API development. If an API or API test is not behaving as you expect, this would be the place where you will go to deep dive while debugging.

Image result for postman console



For API automation using POSTMAN, we need to adopt the following step(s)

  • Recognize common values in every API
    • Store values in Global and Environment variables
    • Pass the variables rather than passing value manually/hardcoded
  • Identify manual values that need to be changed before hitting the API
    • Replace each value with dynamic variable
      • {{$guid}} : Adds a v4 style guid
      • {{$timestamp}}: Adds the current timestamp
      • {{$randomInt}}: Adds a random integer between 0 and 1000
  • Dependency of any API to other API?
    • Order your request accordingly (REST queries from top to bottom)

API documentation

Postman’s API Documentation feature lets you view private API documentation or share public API documentation in a beautifully formatted web page. 

What gets automatically generated?

Documentation for your API includes:

  • Sample requests, headers, and other metadata
  • Descriptions associated with requests, folders, and collections
  • Generated code snippets in some of the most popular programming languages

What you can do manually?

  • You can customize descriptions using Markdown styling with embedded graphics to complement your documentation.
  • Adding comments to the endpoints as shown in image below

Finally click ellipses (…) in the sidebar and select ‘Publish Docs’, as illustrated below:

publish docs
4 Comments
  1. Andrew says

    Love it. Great job summarizing ! I really enjoyed your presentation.

    1. admin says

      Thanks for appreciating.

  2. Saabeeh says

    Nicely compiled with detailed description. Thankyou.

    1. admin says

      thanks for appreciation

Leave A Reply

Your email address will not be published.