Bird
Raised Fist0
Cypresstesting~5 mins

Mochawesome reporter setup in Cypress

Choose your learning style10 modes available
Introduction

Mochawesome reporter helps you see clear and beautiful test reports after running your Cypress tests.

You want to share test results with your team in an easy-to-read format.
You need to keep a record of test runs for future reference.
You want to quickly find which tests passed or failed after running Cypress tests.
You want to generate HTML reports automatically after tests finish.
Syntax
Cypress
1. Install mochawesome, mochawesome-merge, and mochawesome-report-generator:
   npm install --save-dev mochawesome mochawesome-merge mochawesome-report-generator

2. Update cypress.config.js to add mochawesome reporter:
   const { defineConfig } = require('cypress')
   module.exports = defineConfig({
     e2e: {
       reporter: 'mochawesome',
       reporterOptions: {
         reportDir: 'cypress/reports',
         overwrite: false,
         html: false,
         json: true
       }
     }
   })

Make sure to install mochawesome, mochawesome-merge, and mochawesome-report-generator for full reporting features.

Set overwrite: false to keep reports from multiple test runs.

Examples
This config sets Mochawesome as the reporter and saves reports in cypress/reports folder.
Cypress
e2e: {
  reporter: 'mochawesome',
  reporterOptions: {
    reportDir: 'cypress/reports',
    overwrite: false,
    html: false,
    json: true
  }
}
This command merges multiple JSON reports into one file. Then run npx mochawesome-report-generator cypress/reports/report.json to generate HTML.
Cypress
npx mochawesome-merge cypress/reports/*.json > cypress/reports/report.json
Sample Program

This is a full example of setting up Mochawesome reporter in Cypress config. After running tests, you merge JSON reports, generate the HTML report, and open it to see results.

Cypress
// cypress.config.js
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    reporter: 'mochawesome',
    reporterOptions: {
      reportDir: 'cypress/reports',
      overwrite: false,
      html: false,
      json: true
    },
    setupNodeEvents(on, config) {
      // no special events needed for mochawesome
    }
  }
})

// Run tests with:
// npx cypress run

// After tests, merge and generate reports:
// npx mochawesome-merge cypress/reports/*.json > cypress/reports/report.json
// npx mochawesome-report-generator cypress/reports/report.json

// Open the HTML report: cypress/reports/mochawesome-report/mochawesome.html
OutputSuccess
Important Notes

Always run npx mochawesome-merge cypress/reports/*.json > cypress/reports/report.json and npx mochawesome-report-generator cypress/reports/report.json after tests to combine JSON files and generate the HTML report.

You can customize report folder and options in reporterOptions.

Use the HTML report to easily share test results with your team.

Summary

Mochawesome reporter creates clear HTML and JSON test reports for Cypress.

Install mochawesome packages and update cypress.config.js to enable it.

Merge JSON reports and generate HTML after tests to get a complete report.

Practice

(1/5)
1. What is the main purpose of using the mochawesome reporter in Cypress testing?
easy
A. To create test data for Cypress tests
B. To speed up test execution time
C. To automatically fix failing tests
D. To generate clear and detailed HTML and JSON test reports

Solution

  1. Step 1: Understand the role of reporters in Cypress

    Reporters provide a way to view test results in a readable format after tests run.
  2. Step 2: Identify what mochawesome specifically does

    Mochawesome generates detailed HTML and JSON reports that are easy to read and share.
  3. Final Answer:

    To generate clear and detailed HTML and JSON test reports -> Option D
  4. Quick Check:

    Reporter purpose = Generate reports [OK]
Hint: Mochawesome = report generator, not test runner or fixer [OK]
Common Mistakes:
  • Thinking mochawesome speeds up tests
  • Confusing mochawesome with test data tools
  • Assuming mochawesome fixes test failures
2. Which of the following is the correct way to enable mochawesome reporter in cypress.config.js?
easy
A. reporter: 'mochawesome', reporterOptions: { reportDir: 'cypress/reports' }
B. reporter: 'mocha', reporterOptions: { output: 'cypress/reports' }
C. reporter: 'mochawesome', outputDir: 'cypress/reports'
D. reporter: 'mochawesome', reportPath: 'cypress/reports'

Solution

  1. Step 1: Recall the correct reporter property name

    The reporter is set using the key reporter with value 'mochawesome'.
  2. Step 2: Use the correct options key for mochawesome

    The options for mochawesome are passed under reporterOptions, including reportDir for output folder.
  3. Final Answer:

    reporter: 'mochawesome', reporterOptions: { reportDir: 'cypress/reports' } -> Option A
  4. Quick Check:

    Correct keys = reporter + reporterOptions [OK]
Hint: Use reporterOptions, not outputDir or reportPath [OK]
Common Mistakes:
  • Using 'mocha' instead of 'mochawesome'
  • Wrong option keys like outputDir or reportPath
  • Missing reporterOptions wrapper
3. Given this snippet in cypress.config.js:
reporter: 'mochawesome',
reporterOptions: {
  reportDir: 'cypress/reports',
  overwrite: false,
  html: false,
  json: true
}
What will be the result after running tests?
medium
A. HTML and JSON reports will be generated and overwritten each run
B. Only HTML reports will be generated and overwrite previous reports
C. Only JSON reports will be generated without overwriting previous ones
D. No reports will be generated because html is false

Solution

  1. Step 1: Analyze reporterOptions settings

    html is set to false, so no HTML report is generated. json is true, so JSON report is generated.
  2. Step 2: Understand overwrite behavior

    overwrite is false, so new reports will not overwrite existing ones, allowing multiple JSON reports to accumulate.
  3. Final Answer:

    Only JSON reports will be generated without overwriting previous ones -> Option C
  4. Quick Check:

    html=false + json=true + overwrite=false = JSON only, no overwrite [OK]
Hint: html false means no HTML report; overwrite false keeps old reports [OK]
Common Mistakes:
  • Assuming HTML report is generated when html=false
  • Thinking overwrite=false deletes old reports
  • Confusing json and html options
4. You configured mochawesome in cypress.config.js but after running tests, no report files appear. Which fix is most likely correct?
medium
A. Remove reporterOptions from config to fix issue
B. Install mochawesome and mochawesome-merge packages and update config
C. Change reporter to 'mocha' to generate reports
D. Run tests with --no-report flag to enable reports

Solution

  1. Step 1: Check if mochawesome packages are installed

    Mochawesome requires installing both mochawesome and mochawesome-merge packages to generate and merge reports.
  2. Step 2: Verify config and installation

    Without these packages installed, no reports will be created even if config is correct.
  3. Final Answer:

    Install mochawesome and mochawesome-merge packages and update config -> Option B
  4. Quick Check:

    Missing packages = no reports [OK]
Hint: Always install mochawesome and merge packages before running tests [OK]
Common Mistakes:
  • Removing reporterOptions thinking it fixes issue
  • Changing reporter to 'mocha' which doesn't generate mochawesome reports
  • Using wrong CLI flags like --no-report
5. You want to generate a single combined HTML report after running multiple Cypress test runs with mochawesome. Which approach is correct?
hard
A. Use mochawesome-merge to combine JSON reports, then generate HTML from merged JSON
B. Run tests with overwrite: true and html: true to auto-merge reports
C. Set reporter to 'mochawesome-merge' in cypress.config.js to merge reports automatically
D. Run tests multiple times with html: false and manually copy JSON files into one

Solution

  1. Step 1: Understand mochawesome report generation

    Mochawesome generates separate JSON reports per test run; it does not merge automatically.
  2. Step 2: Use mochawesome-merge tool

    mochawesome-merge combines multiple JSON reports into one, which can then be converted to a single HTML report.
  3. Step 3: Confirm other options are incorrect

    overwrite: true overwrites reports, no auto-merge; 'mochawesome-merge' is not a reporter; manual copying is error-prone.
  4. Final Answer:

    Use mochawesome-merge to combine JSON reports, then generate HTML from merged JSON -> Option A
  5. Quick Check:

    Merge JSON then generate HTML = combined report [OK]
Hint: Merge JSON reports first, then create one HTML report [OK]
Common Mistakes:
  • Expecting mochawesome to auto-merge reports
  • Setting reporter to 'mochawesome-merge' which is not valid
  • Manually copying JSON files without merging
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard