范围报告 - base64-img 而不是实际屏幕截图

问题描述 投票:0回答:2

我编写了 C# 代码来获取 Base64 编码的字符串作为屏幕截图,并将其放入 .html 范围报告中。

    private ExtentReports Extent;
    private ExtentTest Test;
------- some other code here ----------

    Test = Extent.CreateTest("name of my test as string");

    public void AddTestFailureScreenshot(string base64ScreenCapture)
    {
        Test.AddScreenCaptureFromBase64String(base64ScreenCapture, "Screenshot on Error:");
    }

    public string ScreenCaptureAsBase64String()
    {
        ITakesScreenshot ts = (ITakesScreenshot)driver;
        Screenshot screenshot = ts.GetScreenshot();
        return screenshot.AsBase64EncodedString;
    }

当报告以 .html 格式生成时,我无法立即看到嵌入的屏幕截图,而是需要单击 base64-img 链接,然后图像才能正常加载(图像显示我们的预生产环境之一已关闭)

这种情况发生在 Firefox 和 Google Chrome 中。我只是想弄清楚我提供的范围报告代码是否有问题,或者浏览器本身的某些配置有问题。

以前有人遇到过类似的问题吗?我只是希望无需任何额外的点击即可显示屏幕截图。

c# webpage-screenshot selenium-extent-report
2个回答
3
投票

您的问题出在 HTML 中,“href”属性用于链接。您必须使用“src”属性。

如本节所示Example

我希望它对您和有此担忧的人有所帮助。

如果您可以将我标记为“正确答案”,我将非常感激。


0
投票
Any one of the below solution will enable thumbnail image preview of base64 image

Solution 1:
Set thumbnailForBase64 flag as true in ExtentSparkReporter.

ExtentSparkReporter sparkReporter = new ExtentSparkReporter("Report.html");
sparkReporter.config().thumbnailForBase64(true);


Solution 2:
Otherwise you can set the thumbnailForBase64 flag in extent-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
    <configuration>
        <theme>STANDARD</theme>
        <encoding>UTF-8</encoding>
        <protocol>HTTPS</protocol>
        <timelineEnabled>true</timelineEnabled>
        <enableOfflineMode>false</enableOfflineMode>
        **<thumbnailForBase64>true</thumbnailForBase64>**
        <documentTitle>Extent Framework</documentTitle>
        <reportName>Build 1</reportName>
        <timeStampFormat>MMM dd, yyyy HH:mm:ss</timeStampFormat>
        <scripts>
            <![CDATA[
        $(document).ready(function() {

        });
      ]]>
        </scripts>

        <!-- custom styles -->
        <styles>
            <![CDATA[

      ]]>
        </styles>

    </configuration>
</extentreports>

This config file should be loaded to the ExtentSparkReporter using the below code.

  ExtentSparkReporter sparkReporter = new ExtentSparkReporter("Report.html");
  sparkReporter.loadXMLConfig("extent-config.xml");

Make sure you give correct location of the extent config file.
© www.soinside.com 2019 - 2024. All rights reserved.