Writing automated tests with Postman – Part 3

We left off part two of this series at a point where we were able to chain multiple requests together through test scripts and environment variables. Chaining requests is extremely handy and is needed for most API testing scenarios. With Postman’s collection runner, you do not need to run each of these requests one after the other though. Using the collection runner, you can execute all requests in a collection with one click. If you haven’t read the previous parts in the series, I would suggest that you start with part 1.

Let’s look at how we can use the collection runner.

  1. Import the Postman collection for part 3 through the Import Collection modal. Switch to the collections sidebar, click on the import icon and enter this URL: https://www.getpostman.com/collections/a0715a8730540e86b569

1-environment

  1. Set up an environment as shown in part 2. Postman keeps environment values separate from a collection to protect sensitive data like username, tokens etc. that might be present in a collection.

  2. Click on the Collection Runner button in the navigation bar.

2-cr

  1. The collection runner window adopts the same basic structure as the main Postman window. On the left, you can see a sidebar that stores all your previous test runs. On the right side, you can see the main collection runner form.

3-collection-runner-main

  1. Running collections is a simple task. All you need to do, is select a collection, an environment (optional), and set the number of iterations (default is 1). While we have discussed data variables before, we’ll cover them in more detail in another article.

  2. Select the “Tutorial – Part 3” collection from the collection dropdown and the “echo.getpostman.com” environment from the environment drop down. We’ll set the number of iterations as 1.

4-cr-with-settings

  1. Hit “Run”. The main screen switches to show that the collection run is in progress. As we just have 2 requests and 1 iteration, the run should get over quickly.

5-cr-results

  1. Once the run is over, you can analyze the run results. Postman also stores your previous run results which let’s you see if your test results have improved over time. Ultimately, your goal would be that 100% of your tests pass. A test which was passing earlier but fails now would be easy to track. We aim to improve the test reporting facilities of Postman a lot more. Expect some really useful features here!

6-cr-requests

This was intended to be a 3-part series initially but we still haven’t reached the automated part of testing APIs yet. We’ll cover this in the 4th part along with an exciting announcement that we are you sure you will love!

The “How to write automated test with Postman” series

  1. Part 1
  2. Part 2
  3. Part 3 (this article)

Update: See how to write tests using the newer PM API (known as the pm.*API).

Author: Abhinav

CEO @ Postman

27 thoughts on “Writing automated tests with Postman – Part 3”

  1. Please can you add support for coffeescript / livescript in the test editor

    1. Coffeescript support is not on the roadmap for now but we’ll definitely consider it.

  2. Please can you add support to edit ‘beforeTests’ and ‘afterTests’ JS code on a per collection and per Folder basis. This is important for setting up and tearing down tests appropriately.

  3. The Collection Runner hangs when i try to run this collection. Do you guys offer live support?

  4. Curious, when loading a collection run test file any capability to chain variables from the file itself? For example. I load a test data json file with value
    {
    “mIdProperty”: “”mId” : {{mid}}”,
    “mid”: “20720”,
    }
    In my request payload I have:
    {
    {{mIdProperty}}
    }

    So when the request payload is made running through the collection runner it would attmempt:

    {
    “mId” : 20720
    }

    I tested this through the GUI using a different environment and created a couple of environment variables.

    Respectively
    mId = “mId” : {{mid}},

    mid = 20720

    When I do a preview for that environment I do see the correct value in the request payload in addition the request goes through as expected.
    {
    “mId” : 20720

    }

    1. However, I believe some of the items I am trying to do could be cured with the suggestion provided by mat taylor below.

        1. Thanks for the link, I have been using what is highlighted in that, however some of the capabilities just slightly don’t cover what I have been attempting. I’m interested to see what will come of the ” ‘beforeTests’ and ‘afterTests’ JS code” mentioned below.

  5. is it possible to reference environment variables within the test editor? i am setting an environment variable in a previous call and attempting to compare the results returned from a new call with the old environment variable, but i keep getting javascript errors because the environment variables are defined by curly braces. how can i fix this?

  6. Can the summary report for the collection runner handle or display conditional tests while running multiple iterations for a collection?. What I am seeing in the summary is whatever the last test executed, that is the one being displayed in the summary.
    if(A) {
    tests[“A”];
    } else {
    tests[“B”];
    Iteration 1 did Test B and Iteration 2 did Test A, I will see only Test A in the request summaries.
    Although the amount of tests on the overview is correct.

    1. Will mark this for a future release. That’s an important issue which we probably didn’t address before.

  7. Soo, how do we run these automatically from the command line (as part of regression tests for example)? Is Newman (the post linked above) the preferred way?

  8. Can the Collection runner Stats report be exported to an excel sheet so as to share with the team.

    1. Right now they can be exported into a JSON file. You can write a generator which can convert it to a format of your liking.

      1. they are killing selenium (-.-). Currently evaluating to use postman and newman for web-scraping jobs of data that could change any moment. Since it is very easy to create steps with postman and the interceptor. Just update collection. Done…. @postmanrestclient:disqus you guys should think about that market;)

  9. Hi All,
    I have a situation where am using BasicAuth (Authorization tab) and passing Username and Password. I want to make this BasicAuth DataDriven(to read Username, Password from external CSV file). Not sure if we can achieve this in Postman?

    Is it also possible to make Hearders tab parameter as DataDriven?

    Thank You

  10. Trying this out in 2018, and the collections URL right at the start doesn’t work. Any links to the updated page? Thanks!

  11. How do we perform a test on the dynamically obtained data(The data that is retrieved from the database for example) in the service response.

Comments are closed.