微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Extent report 5 截图在其他系统中被破坏,在我的本地系统中工作正常

如何解决在 Extent report 5 截图在其他系统中被破坏,在我的本地系统中工作正常

Please check and let me kNow anything need to modify

下面写在基页中的代码

public static String getScreenshot1() throws IOException {
        String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
        TakesScreenshot ts = (TakesScreenshot) driver;
        File source = ts.getScreenshotAs(OutputType.FILE);

    
        String destination = System.getProperty("user.dir") + "/Screenshots/" + dateName + ".png";
        File finalDestination = new File(destination);
        
        FileHandler.copy(source,finalDestination);
        return destination;
    }

下面写在主类中的代码

test.log(Status.PASS,"browser must navigate to Login page",MediaEntityBuilder.createScreenCaptureFromPath(getScreenshot1()).build());

解决方法

为了让屏幕截图在整个系统中可用,我们可以将屏幕截图转换为 base64 字符串,然后将其附加到 ExtentReport 中。

要将屏幕截图路径转换为 ​​base64 图像:

InputStream in = new FileInputStream(getScreenshot1());
byte[] imageBytes = IOUtils.toByteArray(in);
String base64 = Base64.getEncoder().encodeToString(imageBytes);

test.log(Status.PASS,"Attached Screenshot ",MediaEntityBuilder.createScreenCaptureFromBase64String("data:image/png;base64,"+base64).build());

您可以参考范围报告文档 here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。