问题描述
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。