Serenity provides 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 screenshot is saved for before and after each step as shown in the below image. Before this tutorial, refer the previous tutorial on How to generate Serenity Report.
However, recording a large number of screenshots can slow down test execution. So, may be 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 type of options for managing screenshot 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 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 passed test case. We can see that there is no screenshot attached to any of the test step.
Below is the screenshot of failed test case. We can see that there is a screenshot attached to the failed test step only, not all the test steps. In the 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!!