How to take the screenshot of failed test case with test case name? For example: Suppose the test case name is testVelifyLogin(). If it fails then my screenshot name should be testVelifyLogin_time_date.jpg
Please help me how to do this.
i have written code for screen shot as following:
public void onTestFailure(ITestResult iTestResult) {
String path = System.getProperty("user.dir") + "\\TestOutput\\ScreenShots";
DateFormat dateFormat = new SimpleDateFormat("HH_mm_ss_dd_MM");
Calendar cal = Calendar.getInstance();
String date = dateFormat.format(cal.getTime());
File scrFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(path,"screenshot_"+date+".jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
instead of screenshot_ i want the test case name.