My Blog List

Wednesday, October 19, 2011

Selenium - LogPicture in ReportNG generated report

Hi all,

Here is the method you can add under your package to log the screenshot in report generated by ReportNG.
Before that, just remove the lines from your class files under your ReportNG JAR.

Under org.uncommons.reportng.templates.html, edit the below files by extracting the JAR. ie.Remove the lines which is doing some replacement for some characters .(line which have shouldEscaped)
1. class-results.html.vm
2. output.html.vm
Then, add the modified file to JAR.

Then, use the below function to log the screenshot. Add this function to TestNG JAR under the Reporter class which already have log method.

//if I am using webdriver instance
public static void logPicture(Webdriver driver, String imagePath, String errorMessage) { 

  final File tmpScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
  FileUtils.copyFile(tmpScreenshot, new File(imagePath));

   String s = "<a href=\"file:///" + imagePath + "\">" + errorMessage+ "</a>";
   log(s, getCurrentTestResult());

//if I am using defaultSelenium instance
public static void logPicture(Selenium sel, String imagePath, String errorMessage) { 


   String s = "<a href=\"file:///" + imagePath + "\">" + errorMessage+ "</a>";
   log(s, getCurrentTestResult());

So just use the function like below in your selenium script,
Reporter.logPicture("C:\\error1.png", "Error while doing click.")

1 comment:

  1. Hi

    Can you pls attach / send modified reportng / testng JAR file.