我编写了 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 中。我只是想弄清楚我提供的范围报告代码是否有问题,或者浏览器本身的某些配置有问题。
以前有人遇到过类似的问题吗?我只是希望无需任何额外的点击即可显示屏幕截图。
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.