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.
- 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
- 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.
- Click on the Collection Runner button in the navigation bar.
- 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.
- 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.
- 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.
- 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.
- 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!
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
Update: See how to write tests using the newer PM API (known as the pm.*
API).
Please can you add support for coffeescript / livescript in the test editor
Coffeescript support is not on the roadmap for now but we’ll definitely consider it.
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.
Yes. We are working on these.
The Collection Runner hangs when i try to run this collection. Do you guys offer live support?
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
}
However, I believe some of the items I am trying to do could be cured with the suggestion provided by mat taylor below.
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.
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.
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?
Yes. You can use the special environment dictionary to access variables. More details here: http://getpostman.com/docs/jetpacks_writing_tests
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.
Will mark this for a future release. That’s an important issue which we probably didn’t address before.
Has this been fixed or is there any status update for this issue?
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?
@PatrickSF:disqus Yes. Check out this blog article: https://blog.postman.com/index.php/2014/05/12/meet-newman-a-command-line-companion-for-postman/
Can the Collection runner Stats report be exported to an excel sheet so as to share with the team.
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.
are u killing selenium 😛 ?
Haha. Not exactly. Selenium is meant for other use cases. 🙂
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;)
Does post man supports ruby language to automate?
How can I call another test from within my javascript code?
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
Hello, i’m not able to import collection using https://www.postman.com/collections/a0715a8730540e86b569 url. Could you please help me? thanks a lot
Trying this out in 2018, and the collections URL right at the start doesn’t work. Any links to the updated page? Thanks!
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.