Automated testing for GitHub actions & Newman automation from Postman

Soufiane Bouchaara
3 min readJul 4, 2020

Newman is a command-line runner for Postman collections. In other words, it allows a user to run an existing Postman collection through the command line.

Newman is a NodeJS module , for that we need to have nodes installed, to check, simply check the node version on the system using the below command:

Node -v

Installation

You can simply install Newman like any node package using the following command:

npm install -g newman

When it’s installed, you can check its existences:

newman -v

Running Collections Using Newman

To run collections using Newman, you should have any one of the 2.

  • The collection in JSON format.
  • URL of the hosted collection.

The command used to run the Postman collection using Newman is:

newman run {{collectionJsonPath}}

OR

newman run {{collectionUrl}}

Let’s try running a sample collection using Postman.

Go to the Postman application, use any existing Postman collection and export it to JSON form.

Now export the collection to JSON format (collection.json)

Once the collection JSON is obtained, open the terminal and run the collection using Newman run command

newman run collection.json

Once the above command is run, the following output is produced.

GitHub Actions

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub.

In order to run a GitHub Actions workflow automatically we need to create github actionb workflow folder and files.

GitHub Action workflow file

First, we need to setup a new workflow file in GitHub Action Workflow folder, which listens for the repository dispatch event.

More informations please visit: ttps://github.com/features/actions

Workflow File Syntax

Workflow files use YAML syntax, and must have either a .yml or .yaml file extension. If you’re new to YAML and want to learn more, see “Learn YAML in five minutes.

Example:

At the moment of writing this article, the newman action is on pre-release and here’s the repository for it :

As described on their README you can run it in two different ways :

  • Via URL
  • Via Potman API

Passing these IDs along with your Postman API key will run Newman in this method.

See Creating and using secrets for how to add your Postman API to GitHub securely.

Using Newman and github actions

lets create a new worflow file in the following path:

/.github/worflow/newman-github-actions.yml

please find the workflow file for this test automation that’s gtriggered when code is pushed to master or staging branches:

https://gist.github.com/soufiane-bouchaara/358fafe93df6b44d2f9bd86210197043

if you have any question or sugesstioon please feel free to leave a comments

--

--