11package testreport ;
22
33import aquality .selenium .browser .AqualityServices ;
4- import org .apache .logging .log4j .core .util .FileUtils ;
54import org .openqa .selenium .OutputType ;
65import org .openqa .selenium .TakesScreenshot ;
76import org .testng .ITestResult ;
@@ -18,15 +17,15 @@ public class ScreenshotListener extends TestListenerAdapter {
1817 @ Override
1918 public void onTestFailure (ITestResult result ) {
2019 Calendar calendar = Calendar .getInstance ();
21- SimpleDateFormat formatter = new SimpleDateFormat ("dd_MM_yyyy_hh_mm_ss " );
20+ SimpleDateFormat formatter = new SimpleDateFormat ("dd_MM_yyyy_HH_mm_ss " );
2221 String dateString = formatter .format (calendar .getTime ());
2322 String methodName = result .getName ();
24- if (!result .isSuccess () && AqualityServices .isBrowserStarted ()){
25- File scrFile = ((TakesScreenshot )AqualityServices .getBrowser ().getDriver ()).getScreenshotAs (OutputType .FILE );
23+ if (AqualityServices .isBrowserStarted ()) {
2624 try {
25+ File scrFile = ((TakesScreenshot ) AqualityServices .getBrowser ().getDriver ()).getScreenshotAs (OutputType .FILE );
2726 String reportDirectory = String .format ("%s/target/surefire-reports" , new File (System .getProperty ("user.dir" )).getAbsolutePath ());
2827 File destFile = new File (String .format ("%s/failure_screenshots/%s_%s.png" , reportDirectory , methodName , dateString ));
29- FileUtils . makeParentDirs (destFile );
28+ Files . createDirectories (destFile . getParentFile (). toPath () );
3029 Files .copy (scrFile .toPath (), destFile .toPath ());
3130 Reporter .log (String .format ("<a href='%s'> <img src='%s' height='100' width='100'/> </a>" , destFile .getAbsolutePath (), destFile .getAbsolutePath ()));
3231 } catch (IOException e ) {
0 commit comments