-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better API for path to failed screenshot (for inclusion in HTML reports) #18543
Comments
This would be really nice to have. I do very similar thing to include the screenshot in the report. Can someone from Cypress team at least reply to this? |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Well, that's sad. |
Hi @rkrisztian , I will reopen this issue since it appears it was a feature request that was not labelled as such and so got picked up by our stalebot. I will update the labels accordingly and route to our product team for consideration. |
My latest code looks like this, which works even if you import addContext from 'mochawesome/addContext';
import * as Mocha from 'mocha';
Cypress.on('test:after:run', (test, runnable) => {
if (test.state === 'failed') {
const screenshotDir = `../screenshots/${Cypress.spec.name}`;
const screenshotFileBaseName = getScreenshotFileBaseName(test, runnable);
const screenshotFileName = encodeURIComponent(`${screenshotFileBaseName} (failed).png`);
addContext({ test } as Mocha.Context, { title: 'Screenshot', value: `${screenshotDir}/${screenshotFileName}` });
if (Cypress.config('video')) {
const videoFileName = encodeURIComponent(`${Cypress.spec.name}.mp4`);
addContext({ test } as Mocha.Context, { title: 'Video', value: `../videos/${videoFileName}` });
}
}
});
const getScreenshotFileBaseName = (test: Cypress.ObjectLike, runnable: Mocha.Test) => {
const titlePathNormalized = runnable
.titlePath()
.map((title) => title.replace(/[:/<>]/g, '').trim())
.join(' -- ');
return titlePathNormalized + (test.hookName ? ` -- ${test.hookName} hook` : '');
}; |
I noticed that the |
The screenshot patch changes in Cypress 13 make the problem worse: #24052. Now I can no longer use I also checked if the So as long as our tests are organized in directories, now my workaround doesn't even work anymore, and I can't find anything to get the screenshots attached to the test report. :( |
What would you like?
With Cypress 8, I use code like this to add a screenshot in the mochawesome report for failed tests:
With previous versions of Cypress it used to look less hardcoded because I didn't need to deal with absolute paths:
So this API keeps changing, and now I suspect I'm also using internal API, which feels wrong. I need something easier to use and something more stable over time.
Why is this needed?
This is also a problem because:
describe
s, also setting thescreenshotsFolder
to theassets
folder of the HTML report, which feels arguable to me, e.g., https://www.youtube.com/watch?v=NfBLB329jpgOther
No response
The text was updated successfully, but these errors were encountered: