DEV Community

Cover image for Newman integration in the QA process
keycho47 for Bornfight

Posted on • Updated on

Newman integration in the QA process

Newman is a command line Collection Runner for the Postman and we use it in order to continually test API calls on the backend which are in complex forms involving various filters and tags which are sent in URL parameters.

While using Postman Interceptor in browser, all the requests that are called on as a result of using and clicking on the app itself, and which are turned into collections, are sent on the Postman app.

Collections, with the usage of Newman through command line, can run as a simulation of calling up all the requests from a given collection.

Setup

Postman Interceptor

  • Visit the Chrome Web Store and download the interceptor as an extension
  • Click on the satellite icon which showed up in browser. Afterwards, click on the Install Interceptor Bridge on an opened popup window.

Collection preparation

  • Open the Postman app or download it from the web (for an app to work with the interceptor, Postman must be in a desktop version)
  • Open the app you wish to test in the browser in an additional tab.
  • Open the Postman Interceptor on that exact tab and turn the Capture requests option on.
  • All the requests, which are sent from the web app in history tab, will be received on a desktop version of the Postman app.
  • Mark all the requests which are relevant for automatic continuous testing then save them in a collection.
  • Go to Collections tab and click 'edit' above the created collection
    • Open the tab Tests on an open popup window and write the following:
pm.test("Status code is 200", () => {
  pm.expect(pm.response.code).to.eql(200);
});
Enter fullscreen mode Exit fullscreen mode
  • Go to Collections tab and click 'export collections' to export the created collections. Collections are exported in Collection v2.1 (recommended form) and locally saved.

Project Preparation

  • Open the project in a code editor
  • Installation:
npm install -g newman
Enter fullscreen mode Exit fullscreen mode
  • Create a folder 'newman'
  • Move the collection for that project from the local machine to a newman directory.
  • Run:
newman run newman/mycollection.json
Enter fullscreen mode Exit fullscreen mode
  • Create a script in package.json:
"scripts": {
    "newman:run": "newman run newman/mycollection.json"
  },
Enter fullscreen mode Exit fullscreen mode

CI/CD
For this part, u need to choose your preferred tool for CI/CD and create necessary files in the project example JenkinsFile for Jenkins where it's described where and when will your script run.

Top comments (0)