cucumber-js
cucumber-js copied to clipboard
this.attach in AfterAll hook
I want to add a log file as an attachment to report after tests execution. I wanted to use AfterAll hook but according to this comment: https://github.com/cucumber/cucumber-js/issues/1109#issuecomment-400542113 this is impossible. How can I achieve that? Is this possible to import attach method directly to AfterAll hook?
// This is not working as AfterAll hook dosn't have acces to World instance
AfterAll(async function () {
const file = await fs.readFileSync('./features/support/scp_util/file.txt')
this.attach(file, 'text/plain');
});```
@flywojt Did you find a solution to your problem or do you still require assistance?
No, it is not currently possible. This is mainly due to the idea that attachments are added to a particular test and we don't have the concept of adding a file to the run as whole. What is the use case that you want to attach it in after all instead of after?
@kamolins no, I didn't
@charlierudolph I am adding log files with request/response from REST API and another file with information about testing env. For now, I am using step at the end of every feature file but this is not a clean solution, as I am attaching these same files many times.
Are you using a custom reporter or an open source one to generate the report?
In our project we are using TS and we have a static class for storing anything related to the "Test Run" itself, so you could implement something along the lines of that
This would be a great addition as I've ran into the same scenario that @flywojt mentioned where I need to attach some API request result to the report after all test cases have finished.
The core team discussed this and we agreed the following changes to messages could work:
- Add
TestRunStarted.id
- Add
Attachment.testRunStartedId
This way, an attachment made in a global hook could reference the test run rather than a particular step.