How to take screenshot for only failed test cases using selenium web driver ? package SeleniumLearn.COM; import org.testng.annotations.Test; import org.openqa.selenium.TakesScreenshot; import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.WebDriver; import org.testng.annotations.BeforeTest; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; public class TakeScreenshot { Read more about How to take screenshot for only failed test cases using selenium web driver ?