Open In App

Workflows in Postman

Last Updated : 27 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Postman is an API (Application Programming Interface) development tool that helps in creating, testing, and modifying APIs. Powerful features enable to automation of the complex processes involved in API interactions, increasing efficiency and reducing the chance of errors.

Postman has become a must-have for quality analysts and software developers, providing a simple approach to API development and testing. In this article, we will take a thorough look at the idea of workflow in Postman, delve deeper into environment variables, collection runners, and pre-request scripts, and provide practical examples for better understanding.

Workflows in Postman

A systematic way to organize API calls and related setup is with Postman workflows. By eliminating time wasted manually executing each API request, users can develop an automated process that provides the exact parameters and order needed for error-free and fault-tolerant API testing.

workflow-in-postman

API Testing Workflow in Postman

Getting Started with Workflows

Let’s start understanding workflow in Postman,

Step 1: Creating Collections

The first step is to organize API requests into a collection. Collections act as containers for related requests, making them easier to manage and execute as part of a workflow.

1. Open Postman and click on the “Collections” tab.

collection-in-postman

Collection in Postman

2. Click “New Collection” and give it a name, for example, “My Workflow“.

Screenshot-2024-02-13-at-12231

Step 2: Adding Requests to Collections

Now, let’s populate our collection with API requests. For example, Consider testing a Library API with requests to https://library-api.postmanlabs.com/books.

1. Click on your collection.

2. Press “Add a Request” and provide a relevant name example “books“.

Screenshot-2024-02-13-at-12320

Step 3: Setting Up Environments

Postman allows variables to be set individually depending on the environment context. For example, one might have a production environment that points to the live server’s URL and a development environment that points to the local server’s base URL.

1. Click on the icon and select “Environments.”

file

2. Add a new environment, e.g., “Book API Testing,” and set variables like “baseURL“.

Screenshot-2024-02-13-at-10058

3. Select the “Book API Testing” environment from the dropdown menu.

4. Once you select the environment, variables defined in that environment, such as BaseURL, will automatically be applied to the request.

5. Execute API requests with the customized variables.

6. Click on the “Send” button to execute the API request.

7. Review the response to ensure it conforms to expectations based on the selected environment.

Screenshot-2024-02-13-at-11930

Step 4: Tests-Using Workflows for Automating API Testing with Postman

Let’s see how pre-request scripts and collection runners can be used for efficient automating API testing.

Pre-request Script: Run a pre-request script to modify the request before submitting it to the library API.

Follow these steps:

1. Open the request for which you want to execute the pre-request script.

2. Click on the “Pre-Request Script” tab within the request.

3. Use JavaScript to define actions that occur before a request is received. For example, check if the response exists and has Books.

Javascript




// Check if the response exists and has Books
pm.test("Response has Books", function () {
    try {
        const jsonData = pm.response.json();
        pm.expect(jsonData).to.be.an('array').and.to.have.lengthOf.at.least(1);
    } catch (error) {
        console.error("Error parsing or checking the response:", error.message);
    }
});



Screenshot-2024-02-13-at-11571

Pre-request Script

Collection Runners: Collection Runners boost test case performance by automating the execution of multiple queries.

1. Click on the “Runner” tab in the top menu.

2. Select collection (e.g., “My Workflow“) and environment (e.g., “Book API Testing“).

3. Click “Run” to execute the entire collection with the specified environment variables.

Screenshot-2024-02-14-at-12010

Collection Runner

4. Review the test results.

Screenshot-2024-02-14-at-12013-(1)

Tests Results

Sharing and Collaborating on Workflows

Sharing collections, requests, instances, collection folders, APIs, flows, and environments with colleagues. There are several different ways to share an element in Postman:

1. Click on the three dots next to the collection name “My Workflow“.

2. Choose “Export.”

3. Share with people via email or link Individual team members and groups with whom you shared the element will be notified about your request for collaboration.

4. Share the collections to a website or README with the Run in Postman button.

5. Select Via Run in Postman.

6. Select Via API.

7. Select Get collection JSON using the Collection Access Key.

8. Select Generate a new key to create a read-only store access key. This key expires after 60 days of inactivity.

9. To share a link with other users, select Link to Collection in the public workspace to provide a link to the collection. Anyone with this link can view and fork the shared collection.

Advanced Topics in Postman Workflows

Let’s explore some advanced features that will make API testing and development even more powerful-

  1. To add dynamic features to requests, automate processes, and verify responses, use Postman scripts.
  2. Develop an understanding of handling various authentication methods for API requests, including OAuth and API keys.
  3. Understand how to modify processes to suit multiple environments and how to use global variables for consistency between requests.
  4. Run API tests with a variety of inputs using data files like CSV or JSON, enabling broad test coverage.

Use Cases

Let’s explore some practical use cases where these Postman features can take API testing and development to the next level-

  1. Automate testing as part of the development workflow.
  2. Integrate Postman collections into the CI/CD pipeline using Newman.
  3. Set up monitors to periodically test APIs and ensure they meet performance expectations.
  4. Create mock servers for scenarios where actual backend services are unavailable.
  5. Implement effective collaboration strategies for teams working on shared collections.
  6. Version control collections for better team coordination.

Conclusion

In this article on Postman Workflows, we learned the essentials and explored advanced features. Remember, mastering Postman is an ongoing process, so keep experimenting, testing, and innovating. Whether you are a developer, tester, or both, Postman enables you to build and test APIs efficiently. Now, armed with these advanced themes and use cases, go ahead and supercharge your API development experience.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads