A picture speaks a thousand words, but in our case it can save a thousand seconds. It's a good practice to take an image at the point of test failure as it will help us save a lot of time, which is needed to go through the error logs. Also, sometimes images are needed as part of the test case itself. Here are two approaches:
- Embedding a snapshot at the point of failure
- Taking a screenshot and saving it for later use or reference
Embedding a snapshot in a cucumber report becomes fa+irly easy. Cucumber exposes you to the Scenario
interface, which makes it slightly easier to query whether the scenario has failed or passed. For example, refer to the following snapshot of code; we are doing the following step by step:
- The conditional statement helps us check whether the scenario has passed or failed
- We are checking for a failure condition in respect of the scenario
- We instruct the driver instance to take a screenshot at the point of failure:
if (scenario.isFailed()) { final byte...