anshooarora / extentreports-java

Community version of Extent API for Java has moved to https://github.com/extent-framework/
http://extentreports.com
Other
528 stars 318 forks source link

Not able to open screen shot attached in the HTMLreport. #635

Open Hanumant1987 opened 8 years ago

Hanumant1987 commented 8 years ago

Hello Anshu,

I am using version 3 of extentReports with selenium-Testng Framework. I am using direct code without the testng listener.

I am not able to see screen shot in report. Screen shot is attached but not opening.

Can you help. Please find my code below.

public static String CaptureScreenDirPath()
{
    String destDir = "C:\\Orion_Automation\\TestReportScreenShot";
    DateFormat dateFormat1 = new SimpleDateFormat("dd-MMM-yyyy-hh-mm a");
    String destDir1 = destDir + "/" + dateFormat1.format(new Date());
    new File(destDir1).mkdirs();

    String Path = destDir1 ;

    System.out.println(Path);

    return Path;

}

    public static String CaptureScreen(WebDriver driver, String TestName, String DirPath)

{

        DateFormat dateFormat1 = new SimpleDateFormat("dd-MMM-yyyy-hh-mm a");

        String Path = DirPath + "/" + TestName + "_" + dateFormat1.format(new Date());

        System.out.println(Path);

TakesScreenshot oScn = (TakesScreenshot) driver; File oScnShot = oScn.getScreenshotAs(OutputType.FILE); File oDest = new File(Path+".png"); try { FileUtils.copyFile(oScnShot, oDest); } catch (IOException e) {System.out.println(e.getMessage());} return Path+".png"; }

// Calling in the test case

String ImagePath1 = ExtentManager.CaptureScreen(driver,TestName, DirPath); test.log(Status.INFO, "ScreenShot below: " + test.addScreenCaptureFromPath(ImagePath1));

screenshotnotattached

anshooarora commented 8 years ago

This would probably be due to a path issue. What is the value of DirPath?

Does the screenshot open on the system where it was taken?

Hanumant1987 commented 8 years ago

Hello Anshoo,

Thanks a lot for you quick support always.

Yes everything was working fine I got checked path and opening from the path.Now I know now why this issue was coming, this was due to it's incompatibility with Mozilla Firefox. Same is working fine with google chrome. So I think we can close this issue now, or you may treat this as bug in firefox environment in windows.

Having said that, I have 2 more doubts as mentioned below.

  1. I would like to know in any way can I add my company logo in the report ?
  2. Time taken to execute a test case is not showing in test detail. It's showing start time vs total time. I am using version 3? Also version 3 has no Test.Testcase.End functionality , so is it due to this? Do we have some workaround to show time take to execute a test case.

I really appreciate the great work you did. Thanks a lot.

stsvetaj commented 7 years ago

Hi, i am facing the same problem. When i check the url of the image from the web and copy that to browser the screenshot is shown, but from the extendetreport none. Is there any solution. My code below:

            if(result.getStatus()== ITestResult.FAILURE){
                String title = screenshots.getLastScreenshot().toString();
                String dir = System.getProperty("user.dir")+"/"+title;
                test.fail(result.getThrowable());
                test.fail("Screenshot of failed test: "+test.addScreenCaptureFromPath(dir));
            }

screenshot from 2017-04-25 19 01 02