Serenity provides a wide range of options to manage screenshots in the report. By default, Serenity has set option serenity.take.screenshots=BEFORE_AND_AFTER_EACH_STEP, which means the screenshot is saved before and after each step as shown in the below image. Before this tutorial, refer to the previous tutorial on How to generate Serenity Report.
However, recording many screenshots can slow down test execution. So, maybe we like to record the screenshot of failed steps in the scenario. To achieve this flexibility, configure serenity.take.screenshots property in serenity.properties file.
There are various other types of options for managing screenshots in Serenity Report. This property can take the following values:
- FOR_EACH_ACTION: Saves a screenshot at every web element action (like click(), typeAndEnter(), type(), typeAndTab() etc.).
- BEFORE_AND_AFTER_EACH_STEP: Saves a screenshot before and after every step.
- AFTER_EACH_STEP: Saves a screenshot after every step
- FOR_FAILURES: Saves screenshots only for failing steps.
- DISABLED: Doesn’t save screenshots for any steps.
In the below option, I have used FOR_FAILURES option in the serenity.properties file.
serenity.project.name = Serenity and Cucumber Report Demo current.target.version = sprint-1 serenity.take.screenshots = FOR_FAILURES
Below is the screenshot of the passed test case. We can see that there is no screenshot attached to any of the test steps.
Below is the screenshot of the failed test case. We can see that there is a screenshot attached to the failed test step only, not all the test steps. In below example, it is a scenario outline with four different test data. Out of four, only one set of test data has failed. So, the screenshot is generated for the failed step of that particular test data.
We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
2 thoughts on “How to manage screenshots in Serenity Report”
I am not getting the screenshots in the report irrespective of configuring serenity.properties with serenity.take.screenshots.
Where you have created the serenity.properties file?