Extent Report: Not able to see the screenshots on other machine

你。 提交于 2019-12-08 05:15:48

问题


I am able generate the extent reports with screenshots on my local machine. But when i mail the reports to someone else, or open the html on a differant machine, the screenshots are not visible. It says that the path is invalid.

While attaching the screenshot, i am giving the path of my local machine. And it is searching the same path on other machine too. I tried zipping the html and pics in one folder too.

Please help me how to attach the screenshots into html file without local machine dependency.


回答1:


You can do this by using base64 conversion of the obtained screenshots. Use the following code in your framework and try it.

public static String addScreenshot() {
    File scrFile = ((TakesScreenshot) BasePage.driver).getScreenshotAs(OutputType.FILE);
    String encodedBase64 = null;
    FileInputStream fileInputStreamReader = null;
    try {
        fileInputStreamReader = new FileInputStream(scrFile);
        byte[] bytes = new byte[(int)scrFile.length()];
        fileInputStreamReader.read(bytes);
        encodedBase64 = new String(Base64.encodeBase64(bytes));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "data:image/png;base64,"+encodedBase64;
}



回答2:


I faced same issue.

Share the folder in which you are storing the screenshots with everyone and return same path in below method.

public static String getScreenshot(WebDriver oDriver, String ScreenShotName) throws IOException
    {
        String dateName=new SimpleDateFormat("YYYYMMDDHHMMSS").format(new Date());
        TakesScreenshot ts=(TakesScreenshot)oDriver;
        File source=ts.getScreenshotAs(OutputType.FILE);
        String destination=System.getProperty("user.dir")+"/FailedScreenshots/"+ScreenShotName+dateName+".png";
        File finalDestination=new File(destination);
        FileUtils.copyFile(source, finalDestination);

        String Imagepath="file://Machinename/FailedScreenshots/"+ScreenShotName+dateName+".png";
        return Imagepath;
    }

Hope this helps!



来源:https://stackoverflow.com/questions/43062006/extent-report-not-able-to-see-the-screenshots-on-other-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!