How to Capture screenshot of failed test cases in Selenium using scala.

Table of contents
Reading Time: 2 minutes

We write the selenium script for for the all test cases, some time its success and some time it failed. so better is to take the screen shot of failed test cases.

Automation provide the feature to take the screen shot of failed test cases. by this feature we get the exact idea where is our script failed. In selenium script is failed in different different scenario like when some locator has changed or some functionality has change and other thing is some our application issue.

for the failed the screen shot we should use the try catch block.we put the screen capture code inside the catch block. In my example, i am trying  to login in facebook and when i use wrong password then it should be giving a error so whenever i failed to login to facebook, screen shot will be captured.

Code for the capture the screen shot for failed test cases:


Screen Shot of failed test case:


Written by 

Principal Architect at Knoldus Inc