Comments (7)
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.
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.
@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.
@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.
@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.
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.
@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)
- Can the validator package be updated? HOT 1
- SNYK has detected a high severity issue HOT 4
- Feature: Statistics on suite
- Snapshots stopped showing up on reports after upgrade to v6.0.1 HOT 1
- Add option to avoid use of custom fonts (assets) HOT 1
- How can I get the title of my spec file/describe as my HTML report file namne HOT 5
- Unlimit mochawesome report files above 1000 and rename them HOT 1
- .html extension duplication in 6.1.0 HOT 6
- Please consider progressive enhancement to avoid blank pages when CSPs don't allow JS HOT 3
- Pattern UKStagingJsonReports/.jsons/*.json matched no report files HOT 8
- formatDuration raises sometimes an "Expected a finite number" exception (and it displays a blank screen) HOT 1
- Report shows passed steps as pending HOT 3
- Failures array empty in report
- Asset folder is getting generate even after --inline=true argument
- Copy Text from Test Header
- Please add line number for soure code displaying HOT 1
- Failing to use [name] for reportFilename HOT 1
- Test result file types/interfaces
- Unable to format the "context" section of the mochawesome report
- Ability to show hooks duration in the generated report
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mochawesome-report-generator.