@@ -23,8 +23,7 @@ import {
23
23
log ,
24
24
getStorageByPlatform ,
25
25
getStorageByDeviceName ,
26
- resolve ,
27
- fileExists ,
26
+ resolvePath ,
28
27
getReportPath ,
29
28
scroll ,
30
29
findFreePort ,
@@ -44,7 +43,7 @@ import { IRectangle } from "./interfaces/rectangle";
44
43
import { Point } from "./point" ;
45
44
import { ImageHelper } from "./image-helper" ;
46
45
import { ImageOptions } from "./image-options"
47
- import { unlinkSync , writeFileSync } from "fs" ;
46
+ import { unlinkSync , writeFileSync , existsSync } from "fs" ;
48
47
import { DeviceManager } from "../lib/device-manager" ;
49
48
import { extname , basename } from "path" ;
50
49
import { LogType } from "./log-types" ;
@@ -228,39 +227,39 @@ export class AppiumDriver {
228
227
let retries = 10 ;
229
228
while ( retries > 0 && ! hasStarted ) {
230
229
try {
231
- let sessionIfno ;
230
+ let sessionInfo ;
232
231
233
232
try {
234
233
if ( args . sessionId || args . attachToDebug ) {
235
- const sessionIfnos = JSON . parse ( ( ( await getSessions ( args . port ) ) || "{}" ) + '' ) ;
234
+ const sessionInfos = JSON . parse ( ( ( await getSessions ( args . port ) ) || "{}" ) + '' ) ;
236
235
237
- sessionIfno = sessionIfnos . value . filter ( value => args . sessionId ? args . sessionId === value . id : true ) [ 0 ] ;
238
- if ( ! sessionIfno || ! sessionIfno . id ) {
239
- logError ( "No info suitable session found" , sessionIfno ) ;
236
+ sessionInfo = sessionInfos . value . filter ( value => args . sessionId ? args . sessionId === value . id : true ) [ 0 ] ;
237
+ if ( ! sessionInfo || ! sessionInfo . id ) {
238
+ logError ( "No suitable session info found" , sessionInfo ) ;
240
239
process . exit ( 1 ) ;
241
240
}
242
241
243
- args . sessionId = sessionIfno . id ;
244
- args . appiumCaps = sessionIfno . capabilities ;
245
- // remove app to prevent appium installiing it again
242
+ args . sessionId = sessionInfo . id ;
243
+ args . appiumCaps = sessionInfo . capabilities ;
244
+ // remove app to prevent appium from installing app again
246
245
args . appiumCaps . app = "" ;
247
246
248
- if ( sessionIfno . capabilities . automationName ) {
249
- ( < any > args ) . setAutomationNameFromString ( sessionIfno . capabilities . automationName ) ;
247
+ if ( sessionInfo . capabilities . automationName ) {
248
+ ( < any > args ) . setAutomationNameFromString ( sessionInfo . capabilities . automationName ) ;
250
249
}
251
250
252
251
prepareApp ( args ) ;
253
252
if ( ! args . device ) {
254
253
if ( args . isAndroid ) {
255
- args . device = DeviceManager . getDefaultDevice ( args , sessionIfno . capabilities . avd , sessionIfno . capabilities . deviceUDID . replace ( "emulator-" , "" ) , sessionIfno . capabilities . deviceUDID . includes ( "emulator" ) ? DeviceType . EMULATOR : DeviceType . SIMULATOR , sessionIfno . capabilities . desired . platformVersion || sessionIfno . capabilities . platformVersion ) ;
254
+ args . device = DeviceManager . getDefaultDevice ( args , sessionInfo . capabilities . avd , sessionInfo . capabilities . deviceUDID . replace ( "emulator-" , "" ) , sessionInfo . capabilities . deviceUDID . includes ( "emulator" ) ? DeviceType . EMULATOR : DeviceType . SIMULATOR , sessionInfo . capabilities . desired . platformVersion || sessionInfo . capabilities . platformVersion ) ;
256
255
} else {
257
256
args . device = DeviceManager . getDefaultDevice ( args ) ;
258
257
}
259
258
}
260
259
261
260
await driver . attach ( args . sessionId ) ;
262
261
} else {
263
- sessionIfno = await driver . init ( args . appiumCaps ) ;
262
+ sessionInfo = await driver . init ( args . appiumCaps ) ;
264
263
}
265
264
266
265
} catch ( error ) {
@@ -272,10 +271,10 @@ export class AppiumDriver {
272
271
}
273
272
if ( args . verbose ) {
274
273
logInfo ( "Session info" ) ;
275
- console . info ( sessionIfno ) ;
274
+ console . info ( sessionInfo ) ;
276
275
}
277
276
278
- await DeviceManager . applyDeviceAdditionsSettings ( driver , args , sessionIfno ) ;
277
+ await DeviceManager . applyDeviceAdditionsSettings ( driver , args , sessionInfo ) ;
279
278
280
279
hasStarted = true ;
281
280
} catch ( error ) {
@@ -321,7 +320,7 @@ export class AppiumDriver {
321
320
}
322
321
323
322
/**
324
- * Search for element by given text. The seacrch is case insensitive for android
323
+ * Search for element by given text. The search is case insensitive for android
325
324
* @param text
326
325
* @param match
327
326
* @param waitForElement
@@ -346,22 +345,22 @@ export class AppiumDriver {
346
345
/**
347
346
* Search for element by given automationText and waits until the element is displayed.
348
347
* @param text
349
- * @param waitInMiliseconds till element is displayed
348
+ * @param waitInMilliseconds till element is displayed
350
349
*/
351
- public async waitForElement ( automationText : string , waitInMiliseconds : number = this . defaultWaitTime ) : Promise < UIElement > {
350
+ public async waitForElement ( automationText : string , waitInMilliseconds : number = this . defaultWaitTime ) : Promise < UIElement > {
352
351
let element ;
353
352
try {
354
353
element = await this . findElementByAutomationText ( automationText , 100 ) ;
355
354
} catch ( error ) { }
356
355
const startTime = Date . now ( ) ;
357
- while ( ( ! element || ! ( await element . isDisplayed ( ) ) ) && Date . now ( ) - startTime <= waitInMiliseconds ) {
356
+ while ( ( ! element || ! ( await element . isDisplayed ( ) ) ) && Date . now ( ) - startTime <= waitInMilliseconds ) {
358
357
try {
359
358
element = await this . findElementByAutomationText ( automationText , 100 ) ;
360
359
} catch ( error ) { }
361
360
}
362
361
363
362
if ( ! element || ! await element . isDisplayed ( ) ) {
364
- const msg = `Element with automationText: '${ automationText } ' is not dislpayed after ${ waitInMiliseconds } milliseconds.` ;
363
+ const msg = `Element with automationText: '${ automationText } ' is not displayed after ${ waitInMilliseconds } milliseconds.` ;
365
364
logInfo ( msg ) ;
366
365
}
367
366
@@ -381,7 +380,7 @@ export class AppiumDriver {
381
380
}
382
381
383
382
/**
384
- * Search for elements by given text. The seacrch is case insensitive for android
383
+ * Search for elements by given text. The search is case insensitive for android
385
384
* @param text
386
385
* @param match
387
386
* @param waitForElement
@@ -583,23 +582,23 @@ export class AppiumDriver {
583
582
const pathExpectedImage = this . getExpectedImagePath ( imageName ) ;
584
583
585
584
// First time capture
586
- if ( ! fileExists ( pathExpectedImage ) ) {
587
- const pathActualImage = resolve ( this . _storageByDeviceName , imageName . replace ( "." , "_actual." ) ) ;
585
+ if ( ! existsSync ( pathExpectedImage ) ) {
586
+ const pathActualImage = resolvePath ( this . _storageByDeviceName , imageName . replace ( "." , "_actual." ) ) ;
588
587
await this . takeScreenshot ( pathActualImage ) ;
589
588
590
589
if ( rect ) {
591
590
await this . _imageHelper . clipRectangleImage ( rect , pathActualImage ) ;
592
591
}
593
592
594
- const pathActualImageToReportsFolder = resolve ( this . _logPath , basename ( pathActualImage ) ) ;
593
+ const pathActualImageToReportsFolder = resolvePath ( this . _logPath , basename ( pathActualImage ) ) ;
595
594
copy ( pathActualImage , pathActualImageToReportsFolder , false ) ;
596
595
597
596
console . log ( "Remove the 'actual' suffix to continue using the image as expected one " , pathExpectedImage ) ;
598
597
return false ;
599
598
}
600
599
601
600
// Compare
602
- let pathActualImage = await this . takeScreenshot ( resolve ( this . _logPath , imageName . replace ( "." , "_actual." ) ) ) ;
601
+ let pathActualImage = await this . takeScreenshot ( resolvePath ( this . _logPath , imageName . replace ( "." , "_actual." ) ) ) ;
603
602
const pathDiffImage = pathActualImage . replace ( "actual" , "diff" ) ;
604
603
605
604
await this . prepareImageToCompare ( pathActualImage , rect ) ;
@@ -611,18 +610,18 @@ export class AppiumDriver {
611
610
let counter = 1 ;
612
611
timeOutSeconds *= 1000 ;
613
612
while ( ( Date . now ( ) . valueOf ( ) - eventStartTime ) <= timeOutSeconds && ! result ) {
614
- const pathActualImageConter = resolve ( this . _logPath , imageName . replace ( "." , "_actual_" + counter + "." ) ) ;
613
+ const pathActualImageConter = resolvePath ( this . _logPath , imageName . replace ( "." , "_actual_" + counter + "." ) ) ;
615
614
pathActualImage = await this . takeScreenshot ( pathActualImageConter ) ;
616
615
617
616
await this . prepareImageToCompare ( pathActualImage , rect ) ;
618
617
result = await this . _imageHelper . compareImages ( pathActualImage , pathExpectedImage , pathDiffImage , tolerance , toleranceType ) ;
619
618
counter ++ ;
620
619
}
621
620
} else {
622
- if ( fileExists ( pathDiffImage ) ) {
621
+ if ( existsSync ( pathDiffImage ) ) {
623
622
unlinkSync ( pathDiffImage ) ;
624
623
}
625
- if ( fileExists ( pathActualImage ) ) {
624
+ if ( existsSync ( pathActualImage ) ) {
626
625
unlinkSync ( pathActualImage ) ;
627
626
}
628
627
}
@@ -668,7 +667,7 @@ export class AppiumDriver {
668
667
fileName = fileName . concat ( AppiumDriver . pngFileExt ) ;
669
668
}
670
669
671
- const imgPath = await this . takeScreenshot ( resolve ( this . _logPath , fileName ) ) ;
670
+ const imgPath = await this . takeScreenshot ( resolvePath ( this . _logPath , fileName ) ) ;
672
671
return imgPath ;
673
672
}
674
673
@@ -685,7 +684,7 @@ export class AppiumDriver {
685
684
fileName = fileName . concat ( ".xml" ) ;
686
685
}
687
686
688
- const path = resolve ( this . _logPath , fileName ) ;
687
+ const path = resolvePath ( this . _logPath , fileName ) ;
689
688
const xml = await this . source ( ) ;
690
689
writeFileSync ( path , xml . value , 'utf8' ) ;
691
690
}
@@ -719,7 +718,7 @@ export class AppiumDriver {
719
718
this . _logPath = getReportPath ( this . _args ) ;
720
719
}
721
720
722
- const path = resolve ( this . _logPath , fileName ) ;
721
+ const path = resolvePath ( this . _logPath , fileName ) ;
723
722
writeFileSync ( path , deviceLog , 'utf8' ) ;
724
723
} else {
725
724
console . log ( `Log type: ${ logType } is empty!` ) ;
@@ -763,8 +762,8 @@ export class AppiumDriver {
763
762
764
763
public async quit ( ) {
765
764
console . log ( "Killing driver" ) ;
766
- if ( this . _recordVideoInfo && this . _recordVideoInfo [ 'videoRecoringProcess ' ] ) {
767
- this . _recordVideoInfo [ 'videoRecoringProcess ' ] . kill ( "SIGINT" ) ;
765
+ if ( this . _recordVideoInfo && this . _recordVideoInfo [ 'videoRecordingProcess ' ] ) {
766
+ this . _recordVideoInfo [ 'videoRecordingProcess ' ] . kill ( "SIGINT" ) ;
768
767
}
769
768
try {
770
769
if ( ! this . _args . attachToDebug ) {
@@ -834,41 +833,40 @@ export class AppiumDriver {
834
833
} ;
835
834
836
835
private getExpectedImagePath ( imageName : string ) {
837
-
838
836
if ( ! this . _storageByDeviceName ) {
839
837
this . _storageByDeviceName = getStorageByDeviceName ( this . _args ) ;
840
838
}
841
839
842
- let pathExpectedImage = resolve ( this . _storageByDeviceName , imageName ) ;
840
+ let pathExpectedImage = resolvePath ( this . _storageByDeviceName , imageName ) ;
843
841
844
- if ( ! fileExists ( pathExpectedImage ) ) {
842
+ if ( ! existsSync ( pathExpectedImage ) ) {
845
843
if ( ! this . _storageByPlatform ) {
846
844
this . _storageByPlatform = getStorageByPlatform ( this . _args ) ;
847
845
}
848
- pathExpectedImage = resolve ( this . _storageByPlatform , imageName ) ;
846
+ pathExpectedImage = resolvePath ( this . _storageByPlatform , imageName ) ;
849
847
}
850
848
851
- if ( ! fileExists ( pathExpectedImage ) ) {
852
- pathExpectedImage = resolve ( this . _storageByDeviceName , imageName ) ;
849
+ if ( ! existsSync ( pathExpectedImage ) ) {
850
+ pathExpectedImage = resolvePath ( this . _storageByDeviceName , imageName ) ;
853
851
}
854
852
855
853
return pathExpectedImage ;
856
854
}
857
855
858
856
/**
859
857
* Wait specific amount of time before continue execution
860
- * @param miliseconds
858
+ * @param milliseconds
861
859
*/
862
- public async sleep ( miliseconds : number ) {
863
- await this . _driver . sleep ( miliseconds ) ;
860
+ public async sleep ( milliseconds : number ) {
861
+ await this . _driver . sleep ( milliseconds ) ;
864
862
}
865
863
866
864
/**
867
865
* Wait specific amount of time before continue execution
868
- * @param miliseconds
866
+ * @param milliseconds
869
867
*/
870
- public wait ( miliseconds : number ) {
871
- wait ( miliseconds ) ;
868
+ public wait ( milliseconds : number ) {
869
+ wait ( milliseconds ) ;
872
870
}
873
871
874
872
@@ -936,7 +934,7 @@ export class AppiumDriver {
936
934
const imageName = addExt ( image , AppiumDriver . pngFileExt ) ;
937
935
const pathExpectedImage = this . getExpectedImagePath ( imageName ) ;
938
936
939
- if ( ! fileExists ( pathExpectedImage ) ) {
937
+ if ( ! existsSync ( pathExpectedImage ) ) {
940
938
throw new Error ( "The provided image does not exist!!!" ) ;
941
939
}
942
940
const imageAsBase64 = encodeImageToBase64 ( pathExpectedImage ) ;
0 commit comments