Capturing Screenshots on Test Failure

Screenshots provide visual proof of failures and aid in debugging. Add this utility to your Selenium tests:

public void captureScreenshot(String testName) {

File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(screenshot, new File("screenshots/" + testName + ".png"));

}

Do you automate screenshot capturing? Share your methods!

To view or add a comment, sign in

More articles by Aravindh K

Explore topics