Run API tests with Newman and send reports to Telegram

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • Postman-full-collection-for-CRM-ClientBase-v5

    Full request collection for CRM Project ClientBase v5

  • If you are interested, this Postman collection is available here (still growing).

  • Newman

    Newman is a command-line collection runner for Postman

  • Having completed the preparatory steps in Postman and Telegram, I finally created a new project in the IDE, initialized it, and proceeded to install the necessary dependencies. So for running the collection I used Newman which is a command-line Collection Runner for Postman. In order to install Newman locally in the project as a library, used the following command:

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • newman-reporter-htmlextra

    A HTML reporter for Postman's Command Line Runner, Newman. Includes Non Aggregated Runs broken down by Iterations, Skipped Tests, Console Logs and the handlebars helpers module for better custom templates.

  • To be more precise, I often prefer to use Danny Dainton’s html-extra reporter which is an updated version of the standard Newman HTML reporter containing a more in-depth data output and a few helpful extras. 📑

  • telegram-bot-ruby

    Ruby wrapper for Telegram's Bot API

  • Well, for the training example, I chose Telegram because I just wanted to learn more about the capabilities of the Telegram Bot API. To get started, I needed to select an existing or create a new Telegram group to receive notifications and reports there. It could be any Telegram group (public or private). So I created a new group called "API alerts". The most important step was getting my group's chat ID. And I got it very easily with the help of a special bot inside Telegram - the "Get My ID" bot. I just forwarded one message from my newly created group to this bot and already had the chat ID. There were other ways to do this, but this one seemed faster.

  • dotenv

    Loads environment variables from .env for nodejs projects.

  • In addition to using environment variables in the project, I also needed another module dotenv that loads environment variables from a .env file into process.env. After installing this module with the command:

  • deasync

    Turns async function into sync via JavaScript wrapper of Node event loop

  • To avoid the problem of asynchrony and ensure sequential execution of script blocks, I had to turn to the help of the module DeAsync which turns the async function into sync. It was installed with the command:

  • node-fetch

    A light-weight module that brings the Fetch API to Node.js

  • At this stage, I needed to set up sending two API calls to Telegram: the first one with a notification of the successful completion of the collection running and the second one containing an HTML report. These calls were to go immediately after Newman completed his work. To implement this task, it is certainly possible to use any HTTP client libraries for Node.js which are available as npm packages (Axios, Got, SuperAgent, etc.), but I turned to the Fetch API. The following command was used to install it:

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • form-data

    A module to create readable `"multipart/form-data"` streams. Can be used to submit forms and file uploads to other web applications.

  • The next request turned out to be a little more difficult to implement because it had to send a report.html file inside it, which first needed to be converted using the encoding type multipart form-data. Therefore to create readable "multipart/form-data" streams, I needed to use the Form-Data library. In order to install it locally, used the following command:

  • Newman-Telegram-API

    Run your collections with Newman and get html-reports in Telegram

  • This project with detailed installation and usage instructions is completely available here.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts