未显示范围报告图像

Extent Report Image is not displayed

我正在使用 Extent Report 进行 selenium 测试。

截图:

public String captureScreen() throws IOException {
        TakesScreenshot screen = (TakesScreenshot) driver;
        File src = screen.getScreenshotAs(OutputType.FILE);
        String dest = "./reports/" + System.currentTimeMillis() + ".png";
        File target = new File(dest);
        FileUtils.copyFile(src, target);
        return target.getAbsolutePath();    
    }

    public ExtentTest startTestCase(String testName) {
        test = extent.createTest(testName);
        return test;
    }
public void endTestcase() {
        extent.setAnalysisStrategy(AnalysisStrategy.CLASS);
    }

    public void endResult() {
        extent.flush();
    }

要附上我使用以下代码的屏幕截图:

test.pass("Navigated to  Payment Step 1 Page",MediaEntityBuilder.createScreenCaptureFromPath(captureScreen()).build());

但是报告在本地看起来不错..但是我想用电子邮件发送范围报告..图像不显示。

如何解决?

您必须存储和 link 来自共享或 http 位置的图像才能查看它们。或者,发送一个包含所有图像的 zip 文件。不确定通过电子邮件查看报告的效果如何,因为有一个特定的电子邮件模板。

第 1 步:您必须创建一个新方法 getBase64Screenshot() 并将图像转换为 Base64 并在需要时调用此方法 "ActionsClass.java"

public 静态字符串 getBase64Screenshot() 抛出 IOException {

    Date oDate = new Date();
    SimpleDateFormat oSDF = new SimpleDateFormat("yyyyMMddHHmmss");
    String sDate = oSDF.format(oDate);
    String encodedBase64 = null;
    FileInputStream fileInputStream = null;
    TakesScreenshot screenshot = (TakesScreenshot) Base.driver;
    File source = screenshot.getScreenshotAs(OutputType.FILE);
    String destination =System.getProperty("user.dir")+"\Foldername\target\cucumber-reports\"+"Screenshot_" + sDate + ".png";
    File finalDestination = new File(destination);
    FileUtils.copyFile(source, finalDestination);

    try {
        fileInputStream =new FileInputStream(finalDestination);
        byte[] bytes =new byte[(int)finalDestination.length()];
        fileInputStream.read(bytes);
        encodedBase64 = new String(Base64.encodeBase64(bytes));

    }catch (FileNotFoundException e){
        e.printStackTrace();
    }
    return "data:image/png;base64,"+encodedBase64;
}

第 2 步:要在范围报告中附加屏幕截图 (Pass/Fail),我们可以使用 Report.addScreenCaptureFromPath(ActionsClass.getBase64Screenshot());