我可以在本地计算机上生成带有屏幕截图的范围报告。 但是,当我将报告邮寄给其他人,或在不同的计算机上打开 html 时,屏幕截图不可见。它说路径无效。
在附加屏幕截图时,我给出了本地计算机的路径。它也在其他机器上搜索相同的路径。 我也尝试将 html 和图片压缩到一个文件夹中。
请帮助我如何将屏幕截图附加到 html 文件中,而无需本地计算机依赖。
最佳答案
您可以通过对获得的屏幕截图进行 Base64 转换来完成此操作。 在您的框架中使用以下代码并尝试一下。
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;
}
关于java - 范围报告 : Not able to see the screenshots on other machine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43062006/