private File captureScreen ( TestMethod rootMethod ) { byte [ ] screenData = AdapterContainer . globalInstance ( ) . captureScreen ( ) ; if ( screenData == null ) { return null ; } // use encoded name to avoid various possible file name encoding problem // and to escape invalid file name character (Method name may contain such characters // if method is Groovy method, for example). File captureFile = new File ( String . format ( "%s/%s/%s/%03d.png" , captureRootDir , CommonUtils . encodeToSafeAsciiFileNameString ( rootMethod . getTestClass ( ) . getQualifiedName ( ) , StandardCharsets . UTF_8 ) , CommonUtils . encodeToSafeAsciiFileNameString ( rootMethod . getSimpleName ( ) , StandardCharsets . UTF_8 ) , currentCaptureNo ) ) ; currentCaptureNo ++ ; if ( captureFile . getParentFile ( ) != null ) { captureFile . getParentFile ( ) . mkdirs ( ) ; } FileOutputStream stream = null ; try { stream = new FileOutputStream ( captureFile ) ; stream . write ( screenData ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } finally { IOUtils . closeQuietly ( stream ) ; } return captureFile ; }
returns null if not executed