Sereniry.reportRecordData().fromFile() is not working
Johan-Sap opened this issue · 6 comments
Used Serenity BDD Version : 4.0.16 (Also tried upgrading to 4.0.28 but same results)
Java : 19.0.2
Gradle 8.2
In some cases we need to add a generated file to the report. Previously we did this using Serenity.recordReportData().withTitle("Desktop Screenshot").downloadable().fromFile(Paths.get(imagePath));
This would add the image in the report at the correct step. Since we upgraded (or at least from 4.0.19 onwards) we see this method is no longer adding the image. Its not even moving it to the 'downloadable' folder in the target/site/serenity/ directory. That folder is not even created.
After debugging a bit myself I found that within the fromFile(..) method at one point an Optional is verified to be present.
Optional<TestOutcome> outcome = eventBus.getBaseStepListener().latestTestOutcome(); if (outcome.isPresent()) {....
This outcome however remains Optional.empty causing the code to never get into the IF statement where (I assume) the actual moving of the file and connecting it to the right step is being done.
The method to add text Serenity.recordReportData().withTitle("Text").andContents(imagePath);
does work like expected. It seems only files (an image in my case) is not.
With Cucumber 7, it is no longer possible to access the current test outcome during the test execution, so this feature will indeed no longer work.
Thanks for your very quick reply. Is there a workaround possible, or upcoming ? This function is widely used in our automated testing so I would really hate to loose it. It would then come down to collecting all those files and have them as artefacts of the CI/CD run but then they will not be connected to the specific test/step anymore.
As said adding text does still work (and is connected to the correct step) so I am trying to look into how that method works and if that could be reused for attaching files. But you obviously know more about it than me, so feel free to stop me from waisting time.
Feel free to have a look at the code and see if you can see a fix. @cliviu might have some ideas on how to do this as he implemented the Cucumber parallel execution logic. Not sure about timelines - most features are driven by requests from clients with Serenity BDD support contracts, and I don't think this has come up yet.
Hi, I have a working solution locally. Changed the way its added to follow the method used to add text (Add an Event in the List stepEventBusEvents which is used to replay the steps at the end of the test). I tested it in parallel sessions as well and all seems to go as expected. Will be testing a bit more tomorrow just to make sure I haven't overlooked anything.
I did do it without touching other methods in the same classfile, even though I am convinced 2 methods can be refactored to one (the one 1 added and the one that is used for text). But to keep my change separate and minimize impact I decided to leave that for now.
I created a pull request for the fix. I decided to refactor anyway to not have duplicate methods for Text and Files.
4.0.29 has been released and I have seen it working with that version. Closing the ticket.