@@ -3,6 +3,7 @@ import ADB from 'appium-adb';
33import inquirer from 'inquirer' ;
44
55import Logger from '../../../../logger' ;
6+ import { symbols } from '../../../../utils' ;
67import { killEmulatorWithoutWait } from '../../adb' ;
78import { Options , Platform } from '../../interfaces' ;
89import { getBinaryLocation } from '../../utils/common' ;
@@ -12,6 +13,14 @@ import {showConnectedRealDevices, showRunningAVDs} from '../common';
1213export async function disconnect ( options : Options , sdkRoot : string , platform : Platform ) {
1314 try {
1415 const adbLocation = getBinaryLocation ( sdkRoot , platform , 'adb' , true ) ;
16+ if ( adbLocation === '' ) {
17+ Logger . log ( ` ${ colors . red ( symbols ( ) . fail ) } ${ colors . cyan ( 'adb' ) } binary not found.\n` ) ;
18+ Logger . log ( `Run: ${ colors . cyan ( 'npx @nightwatch/mobile-helper android --standalone' ) } to setup missing requirements.` ) ;
19+ Logger . log ( `(Remove the ${ colors . gray ( '--standalone' ) } flag from the above command if setting up for testing.)\n` ) ;
20+
21+ return false ;
22+ }
23+
1524 const adb = await ADB . createADB ( { allowOfflineDevices : true } ) ;
1625 const devices = await adb . getConnectedDevices ( ) ;
1726
@@ -23,42 +32,42 @@ export async function disconnect(options: Options, sdkRoot: string, platform: Pl
2332
2433 const devicesList = devices . map ( ( device ) => device . udid ) ;
2534
26- // Here, options.s represent the device id to disconnect.
35+ // Here, options.deviceId represent the device id to disconnect.
2736 // If the provided device id is not found then prompt the user to select the device.
28- if ( options . s && typeof options . s === 'string' ) {
29- if ( ! devicesList . includes ( options . s ) ) {
37+ if ( options . deviceId && typeof options . deviceId === 'string' ) {
38+ if ( ! devicesList . includes ( options . deviceId ) ) {
3039 Logger . log ( `${ colors . yellow ( 'Device with the provided ID was not found.' ) } \n` ) ;
31- options . s = '' ;
40+ options . deviceId = '' ;
3241 }
33- } else if ( options . s === true ) {
34- // If the --s flag is present without a value then assign it an empty string
42+ } else if ( options . deviceId === true ) {
43+ // If the --deviceId flag is present without a value then assign it an empty string
3544 // to follow the default flow.
36- options . s = '' ;
45+ options . deviceId = '' ;
3746 }
3847
3948 await showConnectedRealDevices ( ) ;
4049 await showRunningAVDs ( ) ;
4150
42- if ( ! options . s ) {
51+ if ( ! options . deviceId ) {
4352 const deviceAnswer = await inquirer . prompt ( {
4453 type : 'list' ,
4554 name : 'device' ,
4655 message : 'Select the device to disconnect:' ,
4756 choices : devicesList
4857 } ) ;
49- options . s = deviceAnswer . device ;
58+ options . deviceId = deviceAnswer . device ;
5059
5160 Logger . log ( ) ;
5261 }
5362
54- if ( ( options . s as string ) . includes ( 'emulator' ) ) {
55- killEmulatorWithoutWait ( sdkRoot , platform , options . s as string ) ;
63+ if ( ( options . deviceId as string ) . includes ( 'emulator' ) ) {
64+ killEmulatorWithoutWait ( sdkRoot , platform , options . deviceId as string ) ;
5665 Logger . log ( colors . green ( 'Successfully shut down the AVD.' ) ) ;
5766
5867 return true ;
5968 }
6069
61- const disconnectionStatus = execBinarySync ( adbLocation , 'adb' , platform , `disconnect ${ options . s } ` ) ;
70+ const disconnectionStatus = execBinarySync ( adbLocation , 'adb' , platform , `disconnect ${ options . deviceId } ` ) ;
6271 if ( disconnectionStatus ?. includes ( 'disconnected' ) ) {
6372 Logger . log ( colors . green ( 'Successfully disconnected the device.' ) ) ;
6473
0 commit comments