One basic question which comes in everyone's mind is : What happens if test case fails? Where was the error in script and How can we capture it?
So, the solutions is always (at least in most of the cases) to take screenshots of webpage when the test run fails.
With one look at the screenshot we can get an idea of where exactly the script got failed. Moreover reading screenshot is easier compare to reading 100's of console errors
To get screenshot on test failure, we should put the entire code in try-catch block. In the catch block we should paste the screenshot code:
public class TakeScreenshot {
WebDriver driver;
@BeforeTest
public void start(){
driver = new FirefoxDriver();
}