Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

this.attach in AfterAll hook #1394

Open
flywojt opened this issue Jul 23, 2020 · 6 comments
Open

this.attach in AfterAll hook #1394

flywojt opened this issue Jul 23, 2020 · 6 comments
Labels
⚡ enhancement Request for new functionality

Comments

@flywojt
Copy link

flywojt commented Jul 23, 2020

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: #1109 (comment)
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'); 
  });```
@kamolins
Copy link
Contributor

@flywojt Did you find a solution to your problem or do you still require assistance?

@charlierudolph
Copy link
Member

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?

@flywojt
Copy link
Author

flywojt commented Sep 16, 2020

@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.

@kamolins
Copy link
Contributor

kamolins commented Sep 16, 2020

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

@aslakhellesoy aslakhellesoy added the ⚡ enhancement Request for new functionality label Feb 2, 2021
@Andrewngabriel
Copy link

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.

@aslakhellesoy
Copy link
Contributor

aslakhellesoy commented Mar 10, 2022

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

5 participants