在区段报告中获取损坏的图像4

vom3gejh  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(270)

我在我的项目版本4.0.9中使用了扩展报告,并在报告中添加了失败时的屏幕截图,添加后很容易生成,但当我尝试打开屏幕截图时,它会显示损坏的图像。
我使用两个类文件生成报告:-
在第一个类文件中,我刚刚配置了report的基本设置,然后将extent report对象返回给我的listener类below:-

package com.parellelFramework.ReportUtils;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentReporterUtils {

    static ExtentReports extentReporter;

    public static ExtentReports extentReportGenerator(){

        String path=System.getProperty("user.dir")+"/Extent-reports/index.html";
        ExtentSparkReporter sparkReporter=new ExtentSparkReporter(path);
        sparkReporter.config().setReportName("Demo insurance Test report");
        sparkReporter.config().setDocumentTitle("Parallel test execution");
        sparkReporter.config().setTheme(Theme.DARK);

        extentReporter=new ExtentReports();
        extentReporter.attachReporter(sparkReporter);
        extentReporter.setSystemInfo("OS NAME",System.getProperty("os.name"));
        extentReporter.setSystemInfo("JAVA VERSION",System.getProperty("java.version"));
        extentReporter.setSystemInfo("MAVEN VERSION",System.getProperty("3.6.3"));
        extentReporter.setSystemInfo("USER LOCATION",System.getProperty("user.country"));
        extentReporter.setSystemInfo("USER TIME",System.getProperty("user.timezone"));
        return extentReporter;
    }
}

之后,我将使用itestlistener类,在该类中我将使用常用的方法,添加日志并将屏幕截图附加到报告中

package com.parellelFramework.ReportUtils;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.parellelFramework.utilities.CommonUtils;
import org.testng.ITestListener;
import org.testng.ITestResult;
import java.io.IOException;

public class ExtentReportListener implements ITestListener{

    ExtentReports reporter;
    ExtentTest extentTest;

    public void onTestStart(ITestResult result) {

        reporter=ExtentReporterUtils.extentReportGenerator();
        extentTest=reporter.createTest(result.getMethod().getMethodName()+" has been started");

    }

    public void onTestSkipped(ITestResult result) {

      extentTest.log(Status.INFO,result.getMethod().getMethodName()+ "has been skipped");
    }

    public void onTestSuccess(ITestResult result) {

        try {

            extentTest.log(Status.PASS,result.getMethod().getMethodName()+" has been successfully completed");
            extentTest.addScreenCaptureFromPath(CommonUtils.TakeScreenshot(result.getMethod().getMethodName()),result.getMethod().getMethodName());
            System.out.println("Screenshot captured and added");
            reporter.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void onTestFailure(ITestResult result) {

        extentTest.log(Status.FAIL,result.getMethod().getMethodName()+"has been failed");
        try {
            extentTest.addScreenCaptureFromPath(CommonUtils.TakeScreenshot(result.getMethod().getMethodName()),result.getMethod().getMethodName());
            System.out.println("Screenshot captured and attached in report");
            reporter.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

现在,当报告生成与截图,然后我得到了破碎的图像截图。我已经尝试使用mediaentitybuilder在报告中附加屏幕截图,但它没有解决问题。所以请帮帮我
附上的是照片reference:-

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题