extentreports-java icon indicating copy to clipboard operation
extentreports-java copied to clipboard

Images not loaded for the failed Results in the extent Reports

Open Yoganand1995 opened this issue 6 years ago • 2 comments

Hi ,

Below is the code I'm using to get the extent reports for my framework and the images are not loaded in the html reports and please guide me on the issue.

 <dependency>
      <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
      <version>5.0.3</version>
    </dependency>

Base class method to get the screenshot


`  public String getScreenshot(String MethodName, WebDriver FailedDriver) throws IOException {
        TakesScreenshot ScrShot = (TakesScreenshot) FailedDriver;
        File Source = ScrShot.getScreenshotAs(OutputType.FILE);
        String DesFile = System.getProperty("user.dir")+"\\reports\\Screenshots\\"+MethodName+".jpg";
        FileUtils.copyFile(Source,new File(DesFile).getAbsoluteFile());
        return DesFile;
    }`

Extent Report class

`public class ExtentReport {
    public static ExtentReports extent;
    public static ExtentReports getReport(){
        String path = System.getProperty("user.dir") + "\\reports\\HtmlReports\\index.html";
        ExtentSparkReporter reporter = new ExtentSparkReporter(path);
        reporter.config().setReportName("Web Automation Results");
        reporter.config().setDocumentTitle("Test Results");
        extent = new ExtentReports();
        extent.attachReporter(reporter);
        extent.setSystemInfo("Tester","Yogananda");
        return extent;
    }
}`

TestNG Listener Method for the fail

`public void onTestFailure(ITestResult result) {
        Test.fail(result.getThrowable());
        WebDriver FailedDriver = null;
        String MethodName = result.getMethod().getMethodName();
        try {
            FailedDriver= (WebDriver)result.getTestClass().getRealClass()
                          .getDeclaredField("Driver").get(result.getInstance());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Test.addScreenCaptureFromPath(getScreenshot(MethodName,FailedDriver),MethodName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }`

screenshot of the issue image issue

Yoganand1995 avatar Sep 07 '20 05:09 Yoganand1995

I ran into this as well, there's no image attached at all

thanhlelgg avatar Sep 08 '20 08:09 thanhlelgg

To fix this, kindly get

  1. the instance of getExtentHtmlReport(); and getExtentReport();
  2. attach reporter
  3. ExtentTest testlog=Reporter.getCurrentStep();
  4. Run screenshot code
  5. testlog.info(addLink, MediaEntityBuilder.createScreenCaptureFromPath(fullPath).build());
  6. flush the extent report

There You GO!! Screenshot 2020-09-11 at 9 34 56 PM

surajgupta7175 avatar Sep 11 '20 16:09 surajgupta7175