Git Product home page Git Product logo

cypress-mochawesome-reporter's Introduction

cypress-mochawesome-reporter

npm node npm npm

Zero config Mochawesome reporter for Cypress with screenshots attached to tests.

Example report

Mochawesome report with fail test screenshot

Cypress compatibility

reporter version cypress version reporter branch
v3 node >= 14
>= 6.7.0
>= 6.2.0 with experimentalRunEvents: true
master
v2 >= 6.7.0
>= 6.2.0 with experimentalRunEvents: true
v2
v1 >= 4.0.0 v1

migration guide from v1 to v2

Setup

This setup tutorial works with Cypress >= v10, looking for older version setup? here

  1. install cypress-mochawesome-reporter

    npm i --save-dev cypress-mochawesome-reporter
    

    or

    yarn add -D cypress-mochawesome-reporter
    
  2. Change cypress reporter & setup hooks

    Edit config file (cypress.config.js by default)

    const { defineConfig } = require('cypress');
    
    module.exports = defineConfig({
      reporter: 'cypress-mochawesome-reporter',
      e2e: {
        setupNodeEvents(on, config) {
          require('cypress-mochawesome-reporter/plugin')(on);
        },
      },
    });

    If you are override before:run or after:run hooks, use this:

    const { defineConfig } = require('cypress');
    const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
    
    module.exports = defineConfig({
      reporter: 'cypress-mochawesome-reporter',
      e2e: {
        setupNodeEvents(on, config) {
          on('before:run', async (details) => {
            console.log('override before:run');
            await beforeRunHook(details);
          });
    
          on('after:run', async () => {
            console.log('override after:run');
            await afterRunHook();
          });
        },
      },
    });
  3. Add to cypress/support/e2e.js

    import 'cypress-mochawesome-reporter/register';
  4. run cypress

Custom options

If you want to customize your HTML report with mochawesome-report-generator flags just add the flags you want to reporterOptions

const { defineConfig } = require('cypress');

module.exports = defineConfig({
  reporter: 'cypress-mochawesome-reporter',
  reporterOptions: {
    charts: true,
    reportPageTitle: 'custom-title',
    embeddedScreenshots: true,
    inlineAssets: true,
    saveAllAttempts: false,
  },
  e2e: {
    setupNodeEvents(on, config) {
      require('cypress-mochawesome-reporter/plugin')(on);
    },
  },
});

Additional reporter options:

name type default description
embeddedScreenshots boolean false Embedded external screenshots into HTML using base64, use with inlineAssets option to produce a single HTML file
quiet boolean false Silence console messages
saveAllAttempts boolean true Save screenshots of all test attempts, set to false to save only the last attempt
debug boolean false Creates log file with debug data

Examples

  1. Simple use of cypress-mochawesome-reporter
  2. Using cypress-multi-reporters
  3. With mochawesome-report-generator flags
  4. Change default screenshots folder in cypress.json

Run npm i in root directory then:

cd examples/<example-project>

npm i
npm test

cypress-mochawesome-reporter's People

Contributors

dependabot[bot] avatar fonata avatar leonardosimoura avatar lironer avatar superwesker1988 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.