Skip to content

Newman & Continuous Integration

Ben Weese edited this page Jun 14, 2019 · 3 revisions

So when looking at the title you may have a couple questions. What is Newman? or What is Continuous Integration? or maybe both. Hopefully I can answer that for you but who knows? Well you do I guess.

So what is Newman. Well Newman is the command line runner for Postman. So you can use it to run your postman collections in terminal or in your continuous integration.

So to install newman first you need to install Node.js and NPM and if you are on a Mac like me you will need to install homebrew first... So if you give a mouse a muffin.

Install homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install NPM brew install node

Install Newman `npm install -g newman'

Now you have and can run the Newman.... Fun fact Newman was the Postman in Seinfeld and that is where it gets it's name.

Ok now you can run your postman collection from the command line. cd into the folder where you have exported your collection and/or environmental variable. Then do the following replacing {{Collection}} with the name of the exported collection and the same with {{Environment}}. If you have no environmental variable you can remove that and the -e

newman run {{Collection}} -e {{Environment}}

You can also run the collection and environment by using the Website links to the postman collection and setting up the API key. Then you just add the following to your newman code with {{Key}} replaced with your api key.

apikey={{Key}}

Continuous Integration

I have ran newman a couple different ways over the years. When using a CI runner on a vm I used the below code that would go through all the collections in a folder and output the test as a html report. I did not like Newman's default template so I looked around and found the Guy who's Github taught me all about postman had his own template that you can find here.

- for collection in ./folder/*.json; do newman run "$collection" -x -e ENV.postman_environment.json -r htmlextra --reporter-htmlextra-darkTheme --reporter-htmlextra-export ./reports/"$collection".html; done

The -x is surrpresses the exit code so all the test can run and report with no issues.

For this repo however I use CircleCI which uses Orbs. The code below is my .circleci/config.yml

version: 2.1
orbs:
  newman: postman/[email protected]
jobs:
  build:
    executor: newman/postman-newman-docker
    steps:
      - checkout
      - newman/newman-run:
          collection: ./newsapi.org.postman_collection.json
          environment: ./newsapi.org.postman_environment.json
          timeout: '1000'

Orbs uses newman 4.4.1 and the GraphQL which can be done in Postman Canary comes in version 4.5.0 of newman. So currently the below is commented out in my code.

      - newman/newman-run:
          collection: ./SWAPI.postman_collection.json
          timeout: '1000'
Clone this wiki locally