代码:
public void tearDown(ITestResult result)
if(result.getStatus()==ITestResult.FAILURE)
String screenshot_path= Utility.captureScreenshot(driver, result.getName());
String image= logger.addScreenCapture(screenshot_path);
logger.log(LogStatus.FAIL, "Title verification", image);
report.endTest(logger);
report.flush();
实用程序类功能:
public static String captureScreenshot(WebDriver driver,String screenshotName)
try
TakesScreenshot ts=(TakesScreenshot)driver;
File source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./Screenshots/"+screenshotName+".png"));
System.out.println("Screenshot taken");
catch (Exception e)
System.out.println("Exception while taking screenshot "+e.getMessage());
return screenshotName;
在范围报告中截取失败的测试用例后,出现图像缩略图但没有图像显示