Giter Site home page Giter Site logo

Comments (7)

elado avatar elado commented on May 24, 2024 26

This worked for me, with both screenshot & video.
There was a missing string replace on the test.title in the original code. Also paths depend on where your screenshots/videos go.

// cypress/support/index.js

import addContext from 'mochawesome/addContext';

const titleToFileName = (title) => title.replace(/[:\/]/g, '');

Cypress.on('test:after:run', (test, runnable) => {
    if (test.state === 'failed') {
        const filename = `${titleToFileName(runnable.parent.title)} -- ${titleToFileName(test.title)} (failed).png`;
        addContext({ test }, `../screenshots/${Cypress.spec.name}/${filename}`);
        addContext({ test }, `../videos/${Cypress.spec.name}.mp4`);
    }
});

from mochawesome-report-generator.

TomRiedl avatar TomRiedl commented on May 24, 2024 9

Thanks @elado it worked great. I had to adjust it a little bit to support more than one level of parents:

import addContext from "mochawesome/addContext";

const titleToFileName = (title) => title.replace(/[:\/]/g, "");

Cypress.on("test:after:run", (test, runnable) =>
{
    if (test.state === "failed")
    {
        let parent = runnable.parent;
        let filename = "";
        while (parent && parent.title)
        {
            filename = `${titleToFileName(parent.title)} -- ${filename}`;
            parent = parent.parent;
        }
        filename += `${titleToFileName(test.title)} (failed).png`;
        addContext({ test }, `../screenshots/${Cypress.spec.name}/${filename}`);
        addContext({ test }, `../videos/${Cypress.spec.name}.mp4`);
    }
});

from mochawesome-report-generator.

krasnoperov avatar krasnoperov commented on May 24, 2024 7

@alucardu, you can use addContext feature of mochawesome:

Put next lines into cypress/support/index.js:

import addContext from 'mochawesome/addContext'
Cypress.on('test:after:run', (test, runnable) => {
  if (test.state === 'failed') {
    addContext({ test }, `./${Cypress.spec.name}/${runnable.parent.title.replace(':', '')} -- ${test.title} (failed).png`)
  }
})

from mochawesome-report-generator.

jackgilbertx avatar jackgilbertx commented on May 24, 2024

@krasnoperov what would this function look like if we were attaching recorded mp4 videos to the report? Ive tried a few variations of what you have above but wasn't able to get it working for some reason.
Thanks in advance

from mochawesome-report-generator.

poplevente avatar poplevente commented on May 24, 2024

@alucardu, you can use addContext feature of mochawesome:

Put next lines into cypress/support/index.js:

import addContext from 'mochawesome/addContext'
Cypress.on('test:after:run', (test, runnable) => {
  if (test.state === 'failed') {
    addContext({ test }, `./${Cypress.spec.name}/${runnable.parent.title.replace(':', '')} -- ${test.title} (failed).png`)
  }
})

@krasnoperov this does not seem to work anymore. is there a new way?

from mochawesome-report-generator.

tamaker avatar tamaker commented on May 24, 2024

Awesome work here! Question -- is it possible to add a 'task' / 'test step' time value to the end of the video URL (i.e. .mp4?t=00:23 ) -- to allow the video to play not the entire mp4, but rather automatically jump to the step that the fail is encountered on?

What would that time value be in terms of a variable name within cypress? I'm guessing it has to exist as a datapoint that we can use.

from mochawesome-report-generator.

noririco avatar noririco commented on May 24, 2024

@elado @TomRiedl Thanks for your comments,

Im using typescript. I get this

const filename = `${titleToFileName( runnable.parent.title )} -- ${titleToFileName( test.title )} (failed).png`;
// Object is possibly 'undefined'.ts(2532)

runnable.parent gives error

(property) Mocha.ITest.parent?: Mocha.ISuite | undefined
@deprecated  .parent has type Mocha.Suite | undefined in Mocha.Test.

any idea ?

UPDATE:
this will be fixed here
cypress-io/cypress#5795

from mochawesome-report-generator.

Related Issues (20)

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.