Record video only for failed test cases

Viewed 2572

How to record videos only for the failed test cases in CI pipeline using cypress, what configuration shall I make to achieve this ... My cypres.json looks like below:

{
    "defaultCommandTimeout": 30000,
    "pageLoadTimeout": 120000,
    "requestTimeout": 30000,
    "responseTimeout": 30000,
    "execTimeout": 30000,
    "taskTimeout": 30000,
    "screenshotsFolder": "cypress/screenshots",
    "trashAssetsBeforeRuns":true,
    "testFiles": "**/*Smoke.spec.ts",
    "video": false,
    "videosFolder": "build/cypress/videos",
    "viewportWidth": 1300,
    "viewportHeight": 1000,
    "animationDistanceThreshold": 50,
    "reporter": "junit",
    "reporterOptions": {
      "mochaFile": "build/cypress/test-output-[hash].xml",
      "toConsole": true,
      "attachments": true
    }
}
2 Answers

As far as I know, Cypress doesn't have the option to only keep videos for a failed test over a passing one - but... recently-released Cypress 6.2.0 includes new events that trigger at interesting points around a spec execution or the whole test run. Cypress developers suggest on Github using these for the exact purpose of deleting video files when the tests are successful. With this technique, once Cypress finishes running the tests, the directory containing the videos (videosFolder in your cypress.json) will contain video files for the failed tests only. It's then up to you to have your CI tool archive this directory. Good luck!

Cypress confirms there's no way to do this right now during cypress run, since the tests are recorded before knowing if they pass or fail.

Besides the plugin for deleting videos that Cycy refers to, Cypress also suggests setting "videoCompression": false if you want to save on compression time.

Related