Tuesday, August 11, 2015

How to add screenshot in ReportNG HTML report


public void catchExceptions(ITestResult result) {
    System.out.println("result" + result);
    String methodName = result.getName();
    System.out.println(methodName);
    if (!result.isSuccess()) {
        try {
        String failureImageFileName =  new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime())+ ".png";
        File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File(failureImageFileName));

// To add screenshot to ReportNG HTML report as a link
  private static final String ESCAPE_PROPERTY = "org.uncommons.reportng.escape-output";
            System.setProperty(ESCAPE_PROPERTY, "false");
   Reporter.setCurrentTestResult(result);
   Reporter.log("failureImageFileName+ "\"> Screenshot
");
(OR)
// To add screenshot to ReportNG HTML report as a image
private static final String ESCAPE_PROPERTY = "org.uncommons.reportng.escape-output";
            System.setProperty(ESCAPE_PROPERTY, "false");
Reporter.log("" +"");


        } catch (IOException e1) {
            e1.printStackTrace();
        }
}
}

No comments:

Post a Comment