Learn from experts and connect with global tech leaders at POST/CON 24. Register by March 26 to save 30%.

Learn more →
X

Writing automated tests with Postman – Part 3

Avatar

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.postman.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).

Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

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

  • Avatar

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

    • Avatar

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

  • Avatar

    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.

    • Avatar

      Yes. We are working on these.

  • Avatar

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

  • Avatar

    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

    }

    • Avatar

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

      • Avatar

        Hi Will,

        You can check out the following article which talks about chaining variables in more detail: https://blog.postman.com/index.php/2014/01/27/extracting-data-from-responses-and-chaining-requests/. It should give you what you are looking for.

        • Avatar

          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.

  • Avatar

    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?

  • Avatar

    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.

    • Avatar

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

      • Avatar

        Has this been fixed or is there any status update for this issue?

  • Avatar

    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?

  • Avatar

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

    • Avatar

      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.

  • Avatar

    are u killing selenium 😛 ?

    • Avatar

      Haha. Not exactly. Selenium is meant for other use cases. 🙂

      • Avatar

        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;)

  • Avatar

    Does post man supports ruby language to automate?

  • Avatar

    How can I call another test from within my javascript code?

  • Avatar

    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

  • Avatar

    Hello, i’m not able to import collection using https://www.postman.com/collections/a0715a8730540e86b569 url. Could you please help me? thanks a lot

  • Avatar

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

  • Avatar

    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.