-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Implementing possibility to attach files to the json reports inside the afterEach hook #1089
Comments
See issue #1051 |
Sorry for taking so long to get back to you, @artem-sokorskyi and @hammzj. As mentioned, this has come up before. I was not entirely convinced of the use-cases, but adding downloads to the report seems akin to screenshots. Ideally I would have liked to have a download API in Cypress and have native support for adding downloads to reports, but based on previous experience I'd say there's little chance of ever seeing this added. I've been trying to come up with the best way of supporting all of the use-cases so far, and I think having a Adding logs from await addCucumberPreprocessorPlugin(on, config, {
onAfterStep({ wasLastStep, attach }) {
if (wasLastStep) {
const logs = ""; // Retrieve logs from cypress-terminal-report.
attach(logs);
}
}
}); Adding downloads (@artem-sokorskyi): await addCucumberPreprocessorPlugin(on, config, {
onAfterStep({ wasLastStep, attach }) {
const downloads = []; // Retrieve recent downloads.
for (const download of downloads) {
attach(download);
}
}
}); Adding resized screenshots (@MDG-JHowley): await addCucumberPreprocessorPlugin(on, config, {
async onAfterStep({ wasLastStep, attach }) {
const screenshots = []; // Retrieve recent screenshots.
for (const screenshot of screenshots) {
attach(resize(screenshot));
}
}
}); |
cool stuff!!! |
@badeball yes this would be great - as you say, we really just need the attach method available in the node environment. |
This, contrary to others, can in fact be run despite test failures. |
So,
If this is the case, this is really cool. I wonder, could this will also get around |
No, this would run purely in the node environment and it cannot call back into the browser environment. |
This is necessary for EG. consistently adding downloads as attachments, in the absence of a proper "after download api" [1]. I hope and believe that this fixes #1089 [1]. [1] cypress-io/cypress#27779 [2] #1089
This is necessary for EG. consistently adding downloads as attachments, in the absence of a proper "after download api" [1]. I hope and believe that this fixes #1089 [1]. [1] cypress-io/cypress#27779 [2] #1089
I've released the above-mentioned API with v19.0.0. You can read more about it here. I hope this gives you the ability to attach files "post test" (albeit as part of the last step, as there are no "test scoped" attachments in Cucumber). |
This is awesome! I'll need to test it out in the next week or so. Thanks for adding this |
@badeball is there anyway to pass the current test details into this hook? |
What do you have in mind specifically? |
Well ideally the feature/spec and scenario/test names and whether the test has failed at that point. I'm trying to attach logs (from For the logs and the videos I need to know the current Feature/spec. For the screenshots the local file path is based on feature/spec, scenario/test and test failure state. My current hack is a custom |
Would it help to have to same arguments as |
Yes, that would be perfect |
I've changed the |
@badeball I've tested this and it is all working nicely, thank you. A minor typo in your docs though:
|
Thanks for the heads up! I've fixed this with 29533f7. |
Current behavior
attach
fn will fail with error message if invoked inside afterEach.> Unexpected state in createStringAttachmentHandler: test-finished (this might be a bug, please report at https://github.com/badeball/cypress-cucumber-preprocessor)
Desired behavior
Attaching successfully the file to the json reports inside the afterEach hook. I suppose the attached file could go under the last executed step of the scenario in the json report
Test code to reproduce
dummy-hook.js
cypress.config.js (remember to disable the "trashAssetsBeforeRuns" option inside the config object)
Next steps:
cy.wrap(1).should('eq', 1)
Logs
Versions
Checklist
[email protected]
(package name has changed and it is no longer the most recent version, see #689).The text was updated successfully, but these errors were encountered: