@@ -35,7 +35,9 @@ import {
35
35
logInfo ,
36
36
prepareDevice ,
37
37
getStorage ,
38
- encodeImageToBase64
38
+ encodeImageToBase64 ,
39
+ ensureReportsDirExists ,
40
+ checkImageLogType
39
41
} from "./utils" ;
40
42
41
43
import { INsCapabilities } from "./interfaces/ns-capabilities" ;
@@ -45,8 +47,10 @@ import { ImageHelper } from "./image-helper";
45
47
import { ImageOptions } from "./image-options"
46
48
import { unlinkSync , writeFileSync , existsSync } from "fs" ;
47
49
import { DeviceManager } from "../lib/device-manager" ;
48
- import { extname , basename } from "path" ;
50
+ import { extname , basename , join } from "path" ;
49
51
import { LogType } from "./log-types" ;
52
+ import { screencapture } from "./helpers/screenshot-manager" ;
53
+ import { LogImageType } from "./enums/log-image-type" ;
50
54
51
55
export class AppiumDriver {
52
56
private static pngFileExt = '.png' ;
@@ -274,8 +278,17 @@ export class AppiumDriver {
274
278
}
275
279
if ( hasStarted ) {
276
280
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
+ }
277
285
} 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
+ }
279
292
}
280
293
281
294
retries -- ;
@@ -566,7 +579,6 @@ export class AppiumDriver {
566
579
}
567
580
568
581
private async compare ( imageName : string , timeOutSeconds : number = 3 , tolerance : number = 0.01 , rect ?: IRectangle , toleranceType ?: ImageOptions ) {
569
-
570
582
if ( ! this . _logPath ) {
571
583
this . _logPath = getReportPath ( this . _args ) ;
572
584
}
@@ -588,6 +600,9 @@ export class AppiumDriver {
588
600
copy ( pathActualImage , pathActualImageToReportsFolder , false ) ;
589
601
590
602
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
+
591
606
return false ;
592
607
}
593
608
@@ -609,8 +624,17 @@ export class AppiumDriver {
609
624
610
625
await this . prepareImageToCompare ( pathActualImage , rect ) ;
611
626
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
+ }
612
631
counter ++ ;
613
632
}
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
+ }
614
638
} else {
615
639
if ( existsSync ( pathDiffImage ) ) {
616
640
unlinkSync ( pathDiffImage ) ;
@@ -653,15 +677,30 @@ export class AppiumDriver {
653
677
} ) ;
654
678
}
655
679
680
+ public testReporterLog ( log : any ) : any {
681
+ if ( this . _args . testReporterLog ) {
682
+ return this . _args . testReporterLog ( log ) ;
683
+ }
684
+ return undefined ;
685
+ }
686
+
656
687
public async logScreenshot ( fileName : string ) {
657
688
if ( ! this . _logPath ) {
658
689
this . _logPath = getReportPath ( this . _args ) ;
659
690
}
660
691
if ( ! fileName . endsWith ( AppiumDriver . pngFileExt ) ) {
661
- fileName = fileName . concat ( AppiumDriver . pngFileExt ) ;
692
+ fileName = fileName . concat ( AppiumDriver . pngFileExt ) . replace ( / \s + / ig , "_" ) ;
662
693
}
663
694
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 ) ;
665
704
return imgPath ;
666
705
}
667
706
@@ -741,6 +780,8 @@ export class AppiumDriver {
741
780
*/
742
781
public async backgroundApp ( minutes : number ) {
743
782
logInfo ( "Sending the currently active app to the background ..." ) ;
783
+ this . _args . testReporterLog ( "Sending the currently active app to the background ..." ) ;
784
+
744
785
await this . _driver . backgroundApp ( minutes ) ;
745
786
}
746
787
@@ -750,7 +791,7 @@ export class AppiumDriver {
750
791
public async hideDeviceKeyboard ( ) {
751
792
try {
752
793
await this . _driver . hideDeviceKeyboard ( ) ;
753
- } catch ( error ) { }
794
+ } catch ( error ) { }
754
795
}
755
796
756
797
public async isKeyboardShown ( ) {
@@ -777,11 +818,19 @@ export class AppiumDriver {
777
818
await this . _driver . quit ( ) ;
778
819
this . _isAlive = false ;
779
820
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
+ }
780
825
} else {
781
826
//await this._webio.detach();
782
827
}
783
828
} catch ( error ) {
784
829
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
+ }
785
834
console . dir ( error ) ;
786
835
}
787
836
}
0 commit comments