我正在尝试在测试失败报告中添加屏幕截图。我根据本教程运行它:http: //toolsqa.com/selenium-webdriver/testng-reporters-asserts/
我的功能
public static void onTestFailure(ITestContext tc, ITestResult result, WebDriver driver) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
String methodName = result.getName();
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
String reportDirectory = new File(System.getProperty("user.dir")).getAbsolutePath() + "\\test-output\\" +tc.getSuite().getXmlSuite().getName();
System.out.printf(reportDirectory);
File destFile = new File((String) reportDirectory+"\\failure_screenshots\\"+methodName+"_"+formater.format(calendar.getTime())+".png");
FileUtils.copyFile(scrFile, destFile);
Reporter.log("<a href='"+ destFile.getAbsolutePath() + "'> <img src='"+ destFile.getAbsolutePath() + "' height='100' width='100'/> </a>");
} catch (IOException e) {
e.printStackTrace();
}
}
问题是屏幕截图出现在适当的位置,但来自 Reporter.log 的链接永远不会进入“Reporter output”视图。
有谁知道我需要做什么才能使它工作?
这是一个带有 maven 的 Java 项目