首页 > 解决方案 > 范围报告中的 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;
    }
}

有人可以帮助解决此问题并在单击后在范围报告中正确显示图像吗?

标签: javaseleniumbase64extentreportsselenium-extent-report

解决方案


你能告诉我你在哪个浏览器中运行这个自动化套件吗?

例如:您在 windows OS 64 位中使用 Chrome 浏览器,那么您需要检查您下载的 chromedriver.exe,即 32 位或 64 位。如果您使用的是 32 位驱动程序,那么这种类型问题来了。

如果您仍然没有找到任何解决方案,请告诉我。


推荐阅读