Newman Postman: command line Collection Runner

Share This Post

Are you using Postman to run your API tests? And are you familiar with Postman Collection runner? Today I’d like to share with you my experience of using Newman, a command line collection runner for Postman. The benefits?  The availability to integrate with your CI.

Let’s create an API test and run it on Postman.

For the test I will use get method, to obtain list of users attacking next endpoint:

https://reqres.in/api/users?page=2

newman postman

Let’s write some tests for this:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
    pm.expect(pm.response.text()).to.include("email");
});
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

Then, it’s time to run these tests from Collection runner:

postman newman4

From here, the next step which we are going to do is exporting the collection as a json.

After it’s successfully exported, we need to install newman. It can be easily installed from npm.

npm install -g newman

And to run it just do:

newman run mycollection.json

postman newman3

There is also the possibility to pass the collection as a url and passing environment variable:

newman run https://www.example.com/collections/test -e dev_environment.json

Providing also some set of options. Like -n flag for iteration-count number, -g for globals file, –folder to run from specific folder name.

And finally, let’s integrate out postman tests with CI. In this example I’ll be using Gitlab CI. Also, I will install reporter and generate an html file which will upload to gitlab artifacts.

newman postman

postman newman5

And the report will look like:

postman newman2

That’s all folks! Happy Testing!

  Automating a Postman test with JMeter

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Subscribe To Our Newsletter

Get updates from our latest tech findings

Have a challenging project?

We Can Work On It Together

apiumhub software development projects barcelona
Secured By miniOrange