QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress › CI, parallelization, reports

What reports, screenshots and videos does Cypress give you?

In cypress run mode Cypress takes a screenshot on failure by itself, while video has been off by default since version 13. Video is switched on with video: true. Reports go through Mocha reporters: spec in the console, junit or json to files, and mochawesome or Allure as third-party ones. Everything lies on the runner's disk, so artifacts are saved by a step with a failure condition.

Cypress · Reports and artifacts

A test failed in CI. What to open first: the console, a screenshot, a video or a report?

A test failed in the pipeline but passes locally. The machine is already gone, so the only thing left of the run is what you managed to save. This lesson is about what Cypress creates by itself, what has to be switched on, which reports exist and how to bring them from CI to a person.

How it works and why. In cypress run mode Cypress takes a screenshot on failure by itself (screenshotOnRunFailure is true by default), while video has been off by default since Cypress 13 and is switched on with video: true. The files lie in cypress/screenshots and cypress/videos. Reports go through Mocha reporters: the built-in spec works in the console, while junit or json write files. Third-party reporters (mochawesome, Allure) are connected through the same reporter field or through a plugin in setupNodeEvents. All of this lies on the runner disk, so without a step that keeps artifacts it vanishes with the machine.

The path of an artifact from CI to a person

cypress runscreenshots, video, XML, JSONfiles on the runner diskvanish with the machineupload-artifact / artifactsif: !cancelled(), expirea person or the tests tabHTML, video, JUnit
Figure 1. The weakest link: files on the runner disk. They must be kept before the job ends.

Which question each one answers (the table helps to choose what to enable):

WhatWhat question it answersWhat it costs
Screenshot on failureWhat the page looked like at the moment of failureLittle space, on by itself
VideoWhat happened before the failure, animations, order of actionsMore space and time, must be turned on
JUnit XMLWhat failed, for the tests tab in CICheap, but with no picture of the page
Mochawesome / AllureAn HTML report, history and trends (Allure)Extra packages and report merging
Test Replay (Cloud)Replay of DOM, network and console after the runCloud and a recorded run

Example: a configured run. The config switches video on, writes JUnit with a separate file per spec ([hash] in the path stops specs from overwriting each other) and deletes videos of specs without failures. Such a recipe exists in the Cypress documentation:

// cypress.config.ts
import { defineConfig } from 'cypress';
import fs from 'node:fs';

export default defineConfig({
  video: true, // false by default
  screenshotOnRunFailure: true, // true by default
  reporter: 'junit',
  reporterOptions: {
    mochaFile: 'results/junit-[hash].xml', // its own file per spec
  },
  e2e: {
    setupNodeEvents(on) {
      // delete videos of specs without failures: fewer artifacts
      on('after:spec', (spec, results) => {
        const failed = results?.tests?.some((test) =>
          test.attempts.some((a) => a.state === 'failed'),
        );
        if (results?.video && !failed) fs.unlinkSync(results.video);
      });
    },
  },
});

Then a CI step keeps everything needed even when the tests failed:

- uses: actions/upload-artifact@v7
  if: ${{ !cancelled() }}
  with:
    name: cypress-results
    path: |
      results/
      cypress/screenshots/
      cypress/videos/
    if-no-files-found: ignore

For an HTML report mochawesome usually writes one JSON per spec, and they have to be merged:

# mochawesome: first JSON from every spec, then merge and HTML
npx mochawesome-merge "cypress/reports/*.json" > merged.json
npx marge merged.json --reportDir report

Limits and alternatives. Video does not show the network and the DOM in detail; for that there is Test Replay in Cypress Cloud. Allure adds history and trends through the allure-cypress package, but it needs the results kept between runs. None of this replaces reading the error text: it is often enough, and the screenshot only confirms a guess. In Playwright the same is built in and stronger: an HTML report with Trace Viewer and settings in use:

// playwright.config.ts
use: {
  trace: 'on-first-retry',
  screenshot: 'only-on-failure',
  video: 'retain-on-failure',
},
reporter: [['html'], ['junit', { outputFile: 'results.xml' }]],

Typical mistakes.

  • Expecting video out of the box: since Cypress 13 it must be switched on, while the screenshot on failure is taken by itself.
  • Keeping artifacts with no condition or only on success(): they are missing exactly on failure.
  • One report file for all specs: the next spec overwrites the previous one. Use [hash] or merging.
  • Keeping the video of every spec with no retention period: artifacts quickly fill the quota.

Check yourself

A test failed in CI and the artifacts have a screenshot but no video, although nobody turned video off in the config. Why?

Answer

Since Cypress 13 video is off by default and must be enabled with video: true, whereas cypress run takes the failure screenshot by itself.

All specs write JUnit to one file, and the CI tab shows only the last one. What do you change?

Answer

Each spec overwrites the file. Add [hash] to mochaFile (for example results/junit-[hash].xml) so each spec writes its own file.

In the interview. Junior: On failure in run mode a screenshot is taken automatically, and video has to be switched on explicitly because it has been off since version thirteen. For HTML reports I use mochawesome, for history and trends Allure through allure-cypress, for CI systems JUnit XML. Middle/Senior: I keep artifacts with the !cancelled() condition and a retention period, and delete videos of specs without failures. For parallel jobs I merge the reports and give each spec its own JUnit file. For deep diagnostics I use Test Replay in Cloud.

More articles in this chapter