0
How to snapshot of the failed test cases?

Open 1 Answers 39 Views Framework-FAQ

1 Answer

0

We use TestNG Assert to check if step is passed or failed, if step is failed, it comes to catch block and we have method in reports called TestStep and we mark isPassed parameter as failed, in that case it will take screenshot using below line of code.

 

public static String captureScreenshot(WebDriver driver,
String screenshotdir) throws IOException {
String randomUUID = UUID.randomUUID().toString();
String storeFileName = screenshotdir + "\\"
+ getFileNameFromURL(driver.getCurrentUrl()) + "_"
+ randomUUID + ".png";
String[] screenshotdirsplit = screenshotdir.split("\\\\");
String fileName = screenshotdirsplit[screenshotdirsplit.length - 1] + "\\"
+ getFileNameFromURL(driver.getCurrentUrl()) + "_"
+ randomUUID + ".png";
File scrFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(storeFileName));
return fileName;
}
answered May 2, 2016 by stbadmin (4,970 points)
...