0
我在我的框架中使用testng,maven,aure。目前我对失败的测试截图保存在万无一失的报告/截图为: 日期时间,类名,方法名 如:09-22-2017_01.13.23_ClassName_Methodname.png获取sscreenshot附件失败的测试引诱报告格式:datetime-classsname-testname selenium,testng,allure
下面是该代码:
@AfterMethod
protected void screenShotIfFail(ITestResult result) throws IOException {
if (!result.isSuccess()) {
takeScreenShot(result.getMethod());
}
}
private void takeScreenShot(String name) throws IOException {
String path = getRelativePath(name);
File screenShot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenShot, new File(path));
String filename = makeScreenShotFileName(name);
System.out.println("Taking Screenshot! " + filename);
Reporter.log("<a href=" + path + " target='_blank' >" + filename
+ "</a>");
}
private void takeScreenShot(ITestNGMethod testMethod) throws IOException {
String nameScreenShot = testMethod.getTestClass().getRealClass()
.getSimpleName()
+ "_" + testMethod.getMethodName();
takeScreenShot(nameScreenShot);
}
private String makeScreenShotFileName(String name) {
DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy_hh.mm.ss");
Date date = new Date();
return dateFormat.format(date) + "_" + name + ".png";
}
private String getRelativePath(String name) throws IOException {
Path path = Paths.get(".", "target", "surefire-reports", "screenShots",
makeScreenShotFileName(name));
File directory = new File(path.toString());
return directory.getCanonicalPath();
}
对于越来越重视对引诱报告,我想@Attachment这样的:
@Attachment(value = "filename", type = "image/png")
private byte[] takeScreenShot(String name) throws IOException {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
截图被越来越重视,以引诱报告,但我怎么能得到它在相同的格式万无一失报告。
谢谢!