@@ -243,22 +243,15 @@ var AndroidEmulatorManager = (function () {
243
243
*/
244
244
AndroidEmulatorManager . prototype . prepareEmulatorForTest = function ( appId ) {
245
245
return this . endRunningApplication ( appId )
246
- . then ( function ( ) { return testUtil_1 . TestUtil . getProcessOutput ( "adb shell pm clear " + appId ) ; } ) . then ( function ( ) { return null ; } ) ;
246
+ . then ( function ( ) {
247
+ return commandWithCheckAppExistence ( "adb shell pm clear" , appId ) ;
248
+ } ) ;
247
249
} ;
248
250
/**
249
251
* Uninstalls the app from the emulator.
250
252
*/
251
253
AndroidEmulatorManager . prototype . uninstallApplication = function ( appId ) {
252
- return testUtil_1 . TestUtil . getProcessOutput ( "adb shell pm list packages" )
253
- . then ( function ( output ) {
254
- return output . includes ( appId ) ;
255
- } ) . then ( function ( isAppExist ) {
256
- if ( isAppExist ) {
257
- return testUtil_1 . TestUtil . getProcessOutput ( "adb uninstall " + appId ) . then ( function ( ) { return null ; } ) ;
258
- }
259
-
260
- return null ;
261
- } ) ;
254
+ return commandWithCheckAppExistence ( "adb uninstall" , appId ) ;
262
255
} ;
263
256
AndroidEmulatorManager . ANDROID_EMULATOR_OPTION_NAME = "--androidemu" ;
264
257
AndroidEmulatorManager . DEFAULT_ANDROID_EMULATOR = "emulator" ;
@@ -398,3 +391,16 @@ var IOSEmulatorManager = (function () {
398
391
return IOSEmulatorManager ;
399
392
} ( ) ) ;
400
393
exports . IOSEmulatorManager = IOSEmulatorManager ;
394
+
395
+ function commandWithCheckAppExistence ( command , appId ) {
396
+ return testUtil_1 . TestUtil . getProcessOutput ( "adb shell pm list packages" , { noLogCommand : true , noLogStdOut : true , noLogStdErr : true } )
397
+ . then ( ( output ) => {
398
+ return output . includes ( appId ) ;
399
+ } ) . then ( ( isAppExist ) => {
400
+ if ( isAppExist ) {
401
+ return testUtil_1 . TestUtil . getProcessOutput ( `${ command } ${ appId } ` ) . then ( function ( ) { return null ; } ) ;
402
+ }
403
+ console . log ( `Command "${ command } " is skipped because the application has not yet been installed` )
404
+ return null ;
405
+ } ) ;
406
+ }
0 commit comments