@@ -35,7 +35,9 @@ import {
3535 logInfo ,
3636 prepareDevice ,
3737 getStorage ,
38- encodeImageToBase64
38+ encodeImageToBase64 ,
39+ ensureReportsDirExists ,
40+ checkImageLogType
3941} from "./utils" ;
4042
4143import { INsCapabilities } from "./interfaces/ns-capabilities" ;
@@ -45,8 +47,10 @@ import { ImageHelper } from "./image-helper";
4547import { ImageOptions } from "./image-options"
4648import { unlinkSync , writeFileSync , existsSync } from "fs" ;
4749import { DeviceManager } from "../lib/device-manager" ;
48- import { extname , basename } from "path" ;
50+ import { extname , basename , join } from "path" ;
4951import { LogType } from "./log-types" ;
52+ import { screencapture } from "./helpers/screenshot-manager" ;
53+ import { LogImageType } from "./enums/log-image-type" ;
5054
5155export class AppiumDriver {
5256 private static pngFileExt = '.png' ;
@@ -274,8 +278,17 @@ export class AppiumDriver {
274278 }
275279 if ( hasStarted ) {
276280 console . log ( "Appium driver has started successfully!" ) ;
281+ if ( checkImageLogType ( args . testReporter , LogImageType . screenshots ) ) {
282+ args . testReporterLog ( `appium_driver_started` ) ;
283+ args . testReporterLog ( screencapture ( `${ getReportPath ( args ) } /appium_driver_started.png` ) ) ;
284+ }
277285 } else {
278- logError ( "Appium driver is NOT started!" )
286+ logError ( "Appium driver is NOT started!" ) ;
287+ if ( checkImageLogType ( args . testReporter , LogImageType . screenshots ) ) {
288+ ensureReportsDirExists ( args ) ;
289+ args . testReporterLog ( `appium_driver_boot_failure` ) ;
290+ args . testReporterLog ( screencapture ( `${ getReportPath ( args ) } /appium_driver_boot_failure.png` ) ) ;
291+ }
279292 }
280293
281294 retries -- ;
@@ -566,7 +579,6 @@ export class AppiumDriver {
566579 }
567580
568581 private async compare ( imageName : string , timeOutSeconds : number = 3 , tolerance : number = 0.01 , rect ?: IRectangle , toleranceType ?: ImageOptions ) {
569-
570582 if ( ! this . _logPath ) {
571583 this . _logPath = getReportPath ( this . _args ) ;
572584 }
@@ -588,6 +600,9 @@ export class AppiumDriver {
588600 copy ( pathActualImage , pathActualImageToReportsFolder , false ) ;
589601
590602 console . log ( "Remove the 'actual' suffix to continue using the image as expected one " , pathExpectedImage ) ;
603+ this . _args . testReporterLog ( basename ( pathActualImage ) ) ;
604+ this . _args . testReporterLog ( join ( this . _logPath , basename ( pathActualImage ) ) ) ;
605+
591606 return false ;
592607 }
593608
@@ -609,8 +624,17 @@ export class AppiumDriver {
609624
610625 await this . prepareImageToCompare ( pathActualImage , rect ) ;
611626 result = await this . _imageHelper . compareImages ( pathActualImage , pathExpectedImage , pathDiffImage , tolerance , toleranceType ) ;
627+ if ( checkImageLogType ( this . _args . testReporter , LogImageType . everyImage ) ) {
628+ this . _args . testReporterLog ( "Actual image: " ) ;
629+ this . _args . testReporterLog ( join ( this . _logPath , basename ( pathActualImage ) ) ) ;
630+ }
612631 counter ++ ;
613632 }
633+
634+ if ( ! checkImageLogType ( this . _args . testReporter , LogImageType . everyImage ) ) {
635+ this . _args . testReporterLog ( "Actual image: " ) ;
636+ this . _args . testReporterLog ( join ( this . _logPath , basename ( pathDiffImage ) ) ) ;
637+ }
614638 } else {
615639 if ( existsSync ( pathDiffImage ) ) {
616640 unlinkSync ( pathDiffImage ) ;
@@ -653,15 +677,30 @@ export class AppiumDriver {
653677 } ) ;
654678 }
655679
680+ public testReporterLog ( log : any ) : any {
681+ if ( this . _args . testReporterLog ) {
682+ return this . _args . testReporterLog ( log ) ;
683+ }
684+ return undefined ;
685+ }
686+
656687 public async logScreenshot ( fileName : string ) {
657688 if ( ! this . _logPath ) {
658689 this . _logPath = getReportPath ( this . _args ) ;
659690 }
660691 if ( ! fileName . endsWith ( AppiumDriver . pngFileExt ) ) {
661- fileName = fileName . concat ( AppiumDriver . pngFileExt ) ;
692+ fileName = fileName . concat ( AppiumDriver . pngFileExt ) . replace ( / \s + / ig , "_" ) ;
662693 }
663694
664- const imgPath = await this . takeScreenshot ( resolvePath ( this . _logPath , fileName ) ) ;
695+ if ( Object . getOwnPropertyNames ( this . _args . testReporter ) . length > 0 ) {
696+ this . testReporterLog ( fileName . replace ( / \. \w + / ig, "" ) ) ;
697+ fileName = join ( this . _logPath , fileName ) ;
698+ fileName = this . testReporterLog ( fileName ) ;
699+ }
700+
701+ fileName = resolvePath ( this . _logPath , fileName )
702+
703+ const imgPath = await this . takeScreenshot ( fileName ) ;
665704 return imgPath ;
666705 }
667706
@@ -741,6 +780,8 @@ export class AppiumDriver {
741780 */
742781 public async backgroundApp ( minutes : number ) {
743782 logInfo ( "Sending the currently active app to the background ..." ) ;
783+ this . _args . testReporterLog ( "Sending the currently active app to the background ..." ) ;
784+
744785 await this . _driver . backgroundApp ( minutes ) ;
745786 }
746787
@@ -750,7 +791,7 @@ export class AppiumDriver {
750791 public async hideDeviceKeyboard ( ) {
751792 try {
752793 await this . _driver . hideDeviceKeyboard ( ) ;
753- } catch ( error ) { }
794+ } catch ( error ) { }
754795 }
755796
756797 public async isKeyboardShown ( ) {
@@ -777,11 +818,19 @@ export class AppiumDriver {
777818 await this . _driver . quit ( ) ;
778819 this . _isAlive = false ;
779820 console . log ( "Driver is dead!" ) ;
821+ if ( checkImageLogType ( this . _args . testReporter , LogImageType . screenshots ) ) {
822+ this . _args . testReporterLog ( `appium_driver_quit` ) ;
823+ this . _args . testReporterLog ( screencapture ( `${ getReportPath ( this . _args ) } /appium_driver_quit.png` ) ) ;
824+ }
780825 } else {
781826 //await this._webio.detach();
782827 }
783828 } catch ( error ) {
784829 if ( this . _args . verbose ) {
830+ if ( checkImageLogType ( this . _args . testReporter , LogImageType . screenshots ) ) {
831+ this . _args . testReporterLog ( `appium_driver_quit_failure` ) ;
832+ this . _args . testReporterLog ( screencapture ( `${ getReportPath ( this . _args ) } /appium_driver_quit_failure.png` ) ) ;
833+ }
785834 console . dir ( error ) ;
786835 }
787836 }
0 commit comments