单击报告中的图像后,硒范围报告中的 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;
}
}
有人可以帮助解决此问题并在单击后在范围报告中正确显示图像吗?