单击报告中的图像后,硒范围报告中的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位驱动程序,那么这种类型的问题来了。
如果您还没有找到任何解决方案,请告诉我。