Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
/ AIO-BEO Public archive

Automation, Integration, and Orchestration for Better Engineering Operations

License

Notifications You must be signed in to change notification settings

evanlindsey/AIO-BEO

Repository files navigation

AIO-BEO

evanlindsey

How to execute Postman Collections through the Monitor API or the Newman Javascript library using Mocha.

Resources

Postman - Generating an API Key

Postman - Forking a Collection

Postman - Creating a Monitor

Retrieving IDs

Collection

Collection ID

Monitor

Monitor ID

Environment Variables

  • API Key -- PM_API_KEY
  • Collection ID -- PM_COLLECTION_ID
  • Monitor ID -- PM_MONITOR_ID

Local Execution

npm install
export PM_API_KEY=***
export PM_COLLECTION_ID=***
export PM_MONITOR_ID=***
npm test
npm run test-newman
npm run test-monitor
npm run test-parallel

Invoke Monitor

// Post Request to Monitor API
const response = await axios.post(
  `https://api.getpostman.com/monitors/${monitorId}/run?apikey=${apiKey}`,
  {}
);

// Format and Log Response
runData = response.data.run;
for (const entry of runData.executions) {
  const req = entry.request;
  const res = entry.response;
  console.log(`\n${entry.item.name}`);
  console.log(
    `${req.method} ${req.url} [${res.code}, ${res.responseSize}B, ${res.responseTime}ms]`
  );
}

Invoke Newman

// Await Newman Response as Promise
await new Promise((resolve, reject) => {
  newman
    .run({
      collection: `https://api.getpostman.com/collections/${collectionId}?apikey=${apiKey}`,
      reporters: ["cli"],
    })
    .on("done", (error, summary) => {
      if (error) {
        reject(error);
      }
      resolve(summary);
    });
});

CircleCI

CircleCI - Setting Environment Variables

CircleCI Env Vars

Configuration

CircleCI - Workflows Configuration Examples

.circleci/config.yml

version: 2.1

orbs:
  node: circleci/node@4.1.0

jobs:
  test:
    executor:
      name: node/default
      tag: "14.15.4"
    steps:
      - checkout
      - node/install-packages
      - run:
          command: npm test
      - store_test_results:
          path: test-results
      - store_artifacts:
          path: test-results/newman/html-results.html

workflows:
  newman-and-monitor:
    jobs:
      - test

Reporting

Monitor Dashboard (Postman)

Monitor Dashboard

Mocha JUnit (CircleCI)

Mocha JUnit

Newman Artifact (CircleCI)

Newman Artifact

Newman htmlextra

Newman htmlextra

NPM Packages

Test Libraries

https://github.com/postmanlabs/newman

https://github.com/mochajs/mocha

Reporters

https://github.com/DannyDainton/newman-reporter-htmlextra

https://github.com/stanleyhlng/mocha-multi-reporters

Utilities

https://github.com/standard-things/esm

https://github.com/axios/axios

https://github.com/chaijs/chai

About

Automation, Integration, and Orchestration for Better Engineering Operations

Resources

License

Stars

Watchers

Forks