【发布时间】:2020-05-21 23:24:05
【问题描述】:
我正在使用这个范围报告:
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.1.5</version>
</dependency>
这是我的方法:
@AfterMethod
public void afterMethod(ITestResult result) {
String methodName = result.getMethod().getMethodName();
if (result.getStatus() == ITestResult.FAILURE) {
String exceptionMessage = Arrays.toString((result.getThrowable().getStackTrace()));
extentTest.fail("<details><summary><b><font color=red>Exception Occured, click to see details:"
+ "</font></b></summary>" + exceptionMessage.replaceAll(",", "<br>") + "</details> \n");
String path = takeScreenshot(result.getMethod().getMethodName());
try {
extentTest.fail(result.getThrowable().getMessage() +
"<br><font color=red>" + "Screenshot of failure" + "</font><br>",
MediaEntityBuilder.createScreenCaptureFromPath(path).build());
} catch (IOException e) {
extentTest.fail("Test Failed, cannot attach screenshot");
}
这是截图:
private String takeScreenshot(String methodName) {
String fileName = getScreenshotName(methodName);
String directory = System.getProperty("user.dir") + "/resources/screenshots/";
new File(directory).mkdirs();
String path = directory + fileName;
try {
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File(path));
System.out.println("**********************************");
System.out.println("Screenshot stored at: " + path);
System.out.println("**********************************");
} catch (IOException e) {
e.printStackTrace();
}
return path;
}
我该如何解决这个问题?提前致谢。
【问题讨论】:
标签: java selenium-webdriver testng extentreports selenium-extent-report