UNPKG

cypress-plugins

Version:

A collection of plugins for cypress created by Chetachi Paschal Enyimiri

239 lines (166 loc) • 7.61 kB
# **@paschal_cheps/cypress-ms-teams-reporter** šŸ†šŸš€ <table align="center" style="margin-bottom:30px;"><tr><td align="center" width="9999" heigth="9999 " > <img src="assets/paschal logo (2).png" alt="paschal Logo" style="margin-top:25px;" align="center"/> # A Cypress reporter that sends test results to Microsoft Teams. </td></tr></table> [![npm version](https://img.shields.io/npm/v/@paschal_cheps/cypress-ms-teams-reporter)](https://www.npmjs.com/package/@paschal_cheps/cypress-ms-teams-reporter) [![npm downloads](https://img.shields.io/npm/dt/@paschal_cheps/cypress-ms-teams-reporter)](https://www.npmjs.com/package/@paschal_cheps/cypress-ms-teams-reporter) [![license](https://img.shields.io/npm/l/@paschal_cheps/cypress-ms-teams-reporter)](https://github.com/qaPaschalE/cypress-plugins/@paschal_cheps/cypress-ms-teams-reporter/blob/main/LICENSE) [![Build Status](https://github.com/qaPaschalE/cypress-plugins/actions/workflows/build.yml/badge.svg)](https://github.com/qaPaschalE/cypress-plugins/actions/workflows/build-cypress-ms-teams-reporter.yml) ![Repo Views](https://github.com/qaPaschalE/cypress-plugins/blob/main/views-badge.svg) [![downloads all time](https://img.shields.io/npm/dt/@paschal_cheps/cypress-ms-teams-reporter.svg?style=flat&color=black&label=lifetime%20downloads)](https://www.npmjs.com/package/@paschal_cheps/cypress-ms-teams-reporter) ## Overview A **Microsoft Teams** reporter for **Cypress test automation** that integrates test reports from **Mochawesome** and sends them as notifications to Teams channels. Supports multiple **CI/CD providers** like GitHub, Bitbucket, CircleCI, and Jenkins. ![Failed Tests](assets/Failed_screenshot.jpeg) ![Passed Tests](assets/Passed_screenshot.jpeg) --- ## **šŸ“Œ Features** āœ… **CI/CD Integration** – Supports GitHub Actions, Bitbucket, CircleCI, Jenkins, or local execution. āœ… **Microsoft Teams Webhook Support** – Sends test execution reports directly to a Teams channel. āœ… **Mochawesome Report Parsing** – Extracts data from Cypress test runs. āœ… **Screenshots & Videos Attachments** – Includes media from test failures. āœ… **Custom Messages** – Add custom text and metadata (Module Name, Team Name, etc.). āœ… **Only Failed Tests Mode** – Send notifications only if tests fail. āœ… **Detailed Logging** – Enable verbose output for debugging. --- ## Prerequisites - **[cypress-mochawesome-reporter](https://www.npmjs.com/package/cypress-mochawesome-reporter)** must be installed and configured in your Cypress setup and saveJson set to true in reporterOptions. ## **šŸ“¦ Installation** ```sh npm install -g @paschal_cheps/cypress-ms-teams-reporter ``` or as a **dev dependency**: ```sh npm install --save-dev @paschal_cheps/cypress-ms-teams-reporter ``` ### **Using `yarn`** ```sh yarn add -D @paschal_cheps/cypress-ms-teams-reporter ``` --- ## **āš™ļø Usage** ### **1ļøāƒ£ Set up Microsoft Teams Webhook** To send reports to Microsoft Teams, you need a webhook URL: - Go to **Microsoft Teams** - Add a **new Incoming Webhook** to your channel - Copy the generated **Webhook URL** ### **2ļøāƒ£ Configure Environment Variables** Create a `.env` file in your project root: ```ini TEAMS_WEBHOOK_URL=https://your-teams-webhook-url GITHUB_TOKEN=your-github-token # Only required for GitHub CI ``` --- ### **3ļøāƒ£ Running the Reporter** #### **šŸ”¹ Default Usage** ```sh npx cypress-ms-teams-reporter --ci-provider=github ``` #### **šŸ”¹ With `.env` file** ```sh dotenv -c npx cypress-ms-teams-reporter --ci-provider=github ``` #### **šŸ”¹ With Custom Report URL** ```sh npx cypress-ms-teams-reporter --custom-url="https://example.com/report.html" ``` #### **šŸ”¹ Only Send Failed Tests** ```sh npx cypress-ms-teams-reporter --only-failed ``` ### Programmatic Usage ```js const { sendTeamsReport } = require("cypress-ms-teams-reporter"); sendTeamsReport({ ciProvider: "github", teamsWebhookUrl: "https://teams.webhook.url", reportDir: "cypress/reports", verbose: true, }); ``` ## Cypress Integration ### Using `task` in `cypress.config.ts` ```ts import { defineConfig } from "cypress"; import { sendTeamsReport } from "cypress-ms-teams-reporter"; export default defineConfig({ e2e: { setupNodeEvents(on, config) { on("task", { sendTeamsReport(options) { return sendTeamsReport(options); }, }); }, }, }); ``` ### Using `on` events in `cypress.config.js` ```js const { sendTeamsReport } = require("cypress-ms-teams-reporter"); module.exports = { e2e: { setupNodeEvents(on, config) { on("after:run", async (results) => { await sendTeamsReport({ ciProvider: "github", teamsWebhookUrl: process.env.TEAMS_WEBHOOK_URL, reportDir: "mochareports", testResults: results, }); }); }, }, }; ``` --- ## **šŸ”§ CLI Options** | Option | Description | Default | | ------------------------- | -------------------------------------------------------------------------- | --------------------- | | `--ci-provider <type>` | Select CI provider (`github`, `bitbucket`, `circleci`, `jenkins`, `local`) | `github` | | `--custom-url <url>` | Provide a custom test report URL | `""` | | `--report-dir <path>` | Path to the Mochawesome report directory | `mochareports` | | `--screenshot-dir <path>` | Cypress screenshot directory | `cypress/screenshots` | | `--video-dir <path>` | Cypress video directory | `cypress/videos` | | `--verbose` | Enable detailed logging | `false` | | `--only-failed` | Send notifications only for failed tests | `false` | | `--custom-text <text>` | Add extra text to the Teams message | `""` | | `--module-name <type>` | Name of the module under test | `""` | | `--team-name <type>` | Name of the team receiving the test report | `""` | --- ## **šŸ–„ļø CI/CD Integration** ### **šŸ”¹ GitHub Actions** Add this step to your workflow: ```yaml - name: Send Cypress Report to Teams run: | npm install dotenv -c npx cypress-ms-teams-reporter --ci-provider=github env: TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` ### **šŸ”¹ Jenkins** ```sh export TEAMS_WEBHOOK_URL="https://your-teams-webhook-url" npx cypress-ms-teams-reporter --ci-provider=jenkins ``` ### **šŸ”¹ Bitbucket Pipelines** ```yaml script: - npx cypress-ms-teams-reporter --ci-provider=bitbucket ``` --- ## **šŸ“Š Report Example (With Pie Chart)** āœ… **Passed:** `80%` 🟢 āŒ **Failed:** `15%` šŸ”“ āš ļø **Pending:** `5%` āš ļø šŸ“Š **Pie Chart:** šŸŸ¢šŸŸ¢šŸŸ¢šŸŸ¢šŸŸ¢šŸŸ¢šŸŸ¢šŸŸ¢šŸ”“šŸ”“āš ļø ## Report Example ## ![Default Failed Report](cypress-ms-teams-reporter/src/img/Failed_screenshot.jpeg) ## ![Default Passed Report](cypress-ms-teams-reporter/src/img/Passed_screenshot.jpeg) ## **šŸ“œ License** MIT License - [@paschal_cheps](https://github.com/paschal-cheps) šŸš€ Happy Testing! šŸŽÆ