Take screenshots for failed test
While doing manual testing we always have the machine in front of us to check what happened when the test case failed. In automation we rely on the assertion message that we print in case of failure. In addition to that we can also have screenshot of the browser in case of failure due to assertion or unavailability of any web element. The code to take the screenshot make use of getScreenshotAs method of TakesScreenshot interface. Following code will take screenshot of the webpage opened by webDriver instance. File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("D:\\testScreenShot.jpg")); Now in order to take screenshot in case of test failure we will use AfterMethod annotation of TestNG. In the AfterMethod annotation we will use ITestResult interface's getStatus() method that returns the test result and in case of failure we can use the above commands to take screenshot. Code snippet to take screensh