Java 将base64屏幕截图添加到extendreport 3.1.5是不成功的
我想用testNG拍摄所有通过和失败的base64截图,下面是我的代码 私有静态扩展端口范围; 私有静态平台; 私有静态字符串reportFileName=“ExtentReports-Version3-Test-Automaton-Report.html”; 私有静态字符串macPath=System.getProperty(“user.dir”)+“/TestReport”; 私有静态字符串windowsPath=System.getProperty(“user.dir”)+“\TestReport”; 私有静态字符串macReportFileLoc=macPath+“/”+reportFileName; 私有静态字符串winReportFileLoc=windowsPath+“\”+reportFileNameJava 将base64屏幕截图添加到extendreport 3.1.5是不成功的,java,collections,Java,Collections,我想用testNG拍摄所有通过和失败的base64截图,下面是我的代码 私有静态扩展端口范围; 私有静态平台; 私有静态字符串reportFileName=“ExtentReports-Version3-Test-Automaton-Report.html”; 私有静态字符串macPath=System.getProperty(“user.dir”)+“/TestReport”; 私有静态字符串windowsPath=System.getProperty(“user.dir”)+“\TestRe
public static ExtentReports getInstance() {
if (extent == null)
createInstance();
return extent;
}
//Create an extent report instance
public static ExtentReports createInstance() {
platform = getCurrentPlatform();
String fileName = getReportFileLocation(platform);
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setTheme(Theme.STANDARD);
htmlReporter.config().setDocumentTitle(fileName);
htmlReporter.config().setEncoding("utf-8");
htmlReporter.config().setReportName(fileName);
extent = new ExtentReports();
extent.setSystemInfo("Author", "Gladson Antony");
extent.setSystemInfo("Browser", Browser);
extent.setSystemInfo("OS", OSName);
extent.setSystemInfo("OS Version", OSVersion);
extent.setSystemInfo("OS Architecture", OSArchitecture);
extent.setSystemInfo("OS Bit", OSBit);
extent.setSystemInfo("JAVA Version",System.getProperty("java.version"));
extent.attachReporter(htmlReporter);
return extent;
}
//Select the extent report file location based on platform
private static String getReportFileLocation (Platform platform) {
String reportFileLocation = null;
switch (platform) {
case MAC:
reportFileLocation = macReportFileLoc;
createReportPath(macPath);
System.out.println("ExtentReport Path for MAC: " + macPath + "\n");
break;
case WINDOWS:
reportFileLocation = winReportFileLoc;
createReportPath(windowsPath);
System.out.println("ExtentReport Path for WINDOWS: " + windowsPath + "\n");
break;
default:
System.out.println("ExtentReport path has not been set! There is a problem!\n");
break;
}
return reportFileLocation;
}
//Create the report path if it does not exist
private static void createReportPath (String path) {
File testDirectory = new File(path);
if (!testDirectory.exists()) {
if (testDirectory.mkdir()) {
System.out.println("Directory: " + path + " is created!" );
} else {
System.out.println("Failed to create directory: " + path);
}
} else {
System.out.println("Directory already exists: " + path);
}
}
//Get current platform
private static Platform getCurrentPlatform () {
if (platform == null) {
String operSys = System.getProperty("os.name").toLowerCase();
if (operSys.contains("win")) {
platform = Platform.WINDOWS;
} else if (operSys.contains("nix") || operSys.contains("nux")
|| operSys.contains("aix")) {
platform = Platform.LINUX;
} else if (operSys.contains("mac")) {
platform = Platform.MAC;
}
}
return platform;
}
下面是我的listerner类,我使用Base64格式为每个通过的测试用例截图
私有静态ExtentReports extent=ExtentManager.createInstance();
私有静态ThreadLocal测试=新ThreadLocal()
提前谢谢你的帮助 Assert是一个只包含静态方法的实用程序类。从未创建过Assert的实例。因此,在映射中存储断言对象没有意义,因为永远不会有任何断言对象。即使这样,
Assert.assertEquals(实际的,预期的)
也不会返回断言:它返回void。在映射中存储void没有意义,特别是当值应该是Assert类型时。你实际上想做什么还不清楚,但可以肯定的是你的代码毫无意义
public synchronized void onStart(ITestContext context) {
System.out.println("Test Suite started!");
}
public synchronized void onFinish(ITestContext context) {
System.out.println(("Test Suite is ending!"));
extent.flush();
}
public synchronized void onTestStart(ITestResult result) {
System.out.println((result.getMethod().getMethodName() + " started!"));
ExtentTest extentTest = extent.createTest(result.getMethod().getMethodName(),
result.getMethod().getDescription());
test.set(extentTest);
}
public synchronized void onTestSuccess(ITestResult result) {
System.out.println((result.getMethod().getMethodName() + " passed!"));
test.get().pass("Test passed");
try {
test.get().pass(result.getTestClass().getName() + "." + result.getMethod().getMethodName(),
MediaEntityBuilder.createScreenCaptureFromBase64String(TestBase.addScreenshot()).build());
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized void onTestFailure(ITestResult result) {
System.out.println((result.getMethod().getMethodName() + " failed!"));
test.get().fail(result.getThrowable());
try {
test.get().fail(result.getTestClass().getName() + "." + result.getMethod().getMethodName(),
MediaEntityBuilder.createScreenCaptureFromBase64String(TestBase.addScreenshot()).build());
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized void onTestSkipped(ITestResult result) {
System.out.println((result.getMethod().getMethodName() + " skipped!"));
test.get().skip(result.getThrowable());
}
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
System.out.println(("onTestFailedButWithinSuccessPercentage for " + result.getMethod().getMethodName()));
}