java - 范围报告中的 Base64 图像屏幕截图在单击报告中的屏幕截图时显示垃圾值
问题描述
单击报告中的图像后,硒范围报告中的 Base64 图像无法正确显示。
搜索各种来源以获得问题解决方案,但在任何地方都没有找到答案
//POM.xml 代码中的依赖关系:-
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
//ExtentReporterListener 代码:-
public synchronized void onTestFailure(ITestResult result) {
System.out.println((result.getMethod().getMethodName() + " failed!"));
test.get().fail("Test failed due to below error");
try {
test.get().fail(result.getThrowable(), MediaEntityBuilder.createScreenCaptureFromPath(TestUtil.getScreenshotExtent()).build());
} catch(IOException e) {
System.err.
println("Exception thrown while updating test fail status " + Arrays.toString(e.getStackTrace()));
}
test.get().getModel().setEndTime(getTime(result.getEndMillis()));
}
//截屏代码:-
public class TestUtil {
public static String getScreenshotExtent() {
String Base64StringofScreenshot = "";
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
byte[] fileContent;
try {
fileContent = FileUtils.readFileToByteArray(src);
Base64StringofScreenshot = "data:image/png;base64," + Base64.getEncoder().encodeToString(fileContent);
} catch(IOException e) {
e.printStackTrace();
}
return Base64StringofScreenshot;
}
}
有人可以帮助解决此问题并在单击后在范围报告中正确显示图像吗?
解决方案
你能告诉我你在哪个浏览器中运行这个自动化套件吗?
例如:您在 windows OS 64 位中使用 Chrome 浏览器,那么您需要检查您下载的 chromedriver.exe,即 32 位或 64 位。如果您使用的是 32 位驱动程序,那么这种类型问题来了。
如果您仍然没有找到任何解决方案,请告诉我。
推荐阅读
- javascript - 在 backgrid 中对自定义(货币)格式的列进行排序
- javascript - Selenium - 在使用之前检查对象是否已定义
- node.js - 使用 Mongoose 模式保存一组子文档
- jinja2 - 使用导出变量在 jinja 中进行 For 循环
- pandas - 是否可以使用一列列表来旋转熊猫数据框?
- javascript - 如何比较 Javascript 中的 2 个数组并制作一个新的真假数组?
- java - Java:如何配置 System.out 以启用自动刷新?
- c# - 为什么我得到值 System.Data.DataRowView?C#
- vagrant - 在主机重新启动后运行 `vagrant up` 和 `vagrant ssh` 而不停止 Vagrant,VM 进入中止/错误状态
- javascript - ReactJS:如何从 useState 钩子中导出变量?