Taking Screen shot of all the test cases may create a memory issue, because we will be running the automation suite multiple times. Moreover, we can see the status of test cases (pass / failed / skipped) in the testing report.
So, what is better is, to take the screen shot of only failed test cases.
Why to take screenshot is required in automation?
1. Screenshot helps us to understand the flow of application whether application is behaving correctly or not.
2. It helps as while doing cross browser testing.
3. Another use is, while doing headless testing, you will not see actual GUI screen, but it will run on backend (ex – by using HTMLUnitBrowser ), in that case, we can track failed tests.
Now, there are two ways how we can take screen shot of failed test case only.
1. By using ITestListener Interface
2. By using ITestResult interface in @AfterMethod
In the below links, both the ways of taking screen shot on test failure are covered.
->> How to take ScreenShot of failed test case using ITestResult interface in @AfterMethodannotation?