【问题标题】:Extent Report Image is not displayed不显示范围报告图像
【发布时间】:2019-01-21 19:25:21
【问题描述】:

我正在使用范围报告进行硒测试。

截屏:

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());

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

如何解决?

【问题讨论】:

    标签: java extentreports


    【解决方案1】:

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

    public static String 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 :在范围报告中附加屏幕截图(通过/失败),我们可以使用 Report.addScreenCaptureFromPath(ActionsClass.getBase64Screenshot());

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 您可以通过云提供商(AWS、Dropbox 等)直接链接,只要在您运行测试时将图像上传到那里。然而,使用共享位置/驱动器是大多数人所做的事情,而且可能更直接。
      猜你喜欢
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多