@@ -11,6 +11,7 @@ import {
1111 DeviceType ,
1212 sortDescByApiLevelPredicate
1313} from "mobile-devices-controller" ;
14+ import { isRegExp } from "util" ;
1415
1516export class DeviceManager implements IDeviceManager {
1617 private static _emulators : Map < string , IDevice > = new Map ( ) ;
@@ -25,7 +26,7 @@ export class DeviceManager implements IDeviceManager {
2526 const token = process . env [ "DEVICE_TOKEN" ] || process . env . npm_config_deviceToken ;
2627 device . token = token && token . replace ( "emulator-" , "" ) ;
2728 device . name = process . env [ "DEVICE_NAME" ] || device . name ;
28-
29+
2930 DeviceManager . cleanUnsetProperties ( device ) ;
3031
3132 if ( args . ignoreDeviceController ) {
@@ -45,8 +46,7 @@ export class DeviceManager implements IDeviceManager {
4546 return device ;
4647 }
4748
48- const searchQuery = args . appiumCaps . udid ? { token : args . appiumCaps . udid } : device ;
49-
49+ const searchQuery = args . appiumCaps . udid ? { token : args . appiumCaps . udid } : Object . assign ( device ) ;
5050 const foundDevices = ( await DeviceController . getDevices ( searchQuery ) )
5151 . sort ( ( a , b ) => sortDescByApiLevelPredicate ( a , b ) ) ;
5252
@@ -75,20 +75,22 @@ export class DeviceManager implements IDeviceManager {
7575
7676 if ( foundDevices && foundDevices . length > 0 ) {
7777 let deviceStatus = args . reuseDevice ? Status . BOOTED : Status . SHUTDOWN ;
78- device = DeviceController . filter ( foundDevices , { status : deviceStatus } ) [ 0 ] ;
78+ device = DeviceController . filter ( foundDevices , { status : deviceStatus } )
79+ . filter ( d => d . type !== DeviceType . TV && d . type !== DeviceType . WATCH ) [ 0 ] ;
7980
8081 // If there is no shutdown device
8182 if ( ! device || ! device . status ) {
8283 deviceStatus = args . reuseDevice ? Status . SHUTDOWN : Status . BOOTED ;
83- device = DeviceController . filter ( foundDevices , { status : deviceStatus } ) [ 0 ] ;
84+ device = DeviceController . filter ( foundDevices , { status : deviceStatus } )
85+ . filter ( d => d . type !== DeviceType . TV && d . type !== DeviceType . WATCH ) [ 0 ] ;
8486 }
8587
8688 // If the device should not be reused we need to shutdown device and boot a clean instance
8789 let startDeviceOptions = args . startDeviceOptions || undefined ;
8890 if ( ! args . reuseDevice && device . status !== Status . SHUTDOWN ) {
8991 await DeviceController . kill ( device ) ;
9092 device . status = Status . SHUTDOWN ;
91- startDeviceOptions = device . type === DeviceType . EMULATOR ? "-wipe-data -no-snapshot-load -no-boot-anim -no-audio" : "" ;
93+ startDeviceOptions = device . type === DeviceType . EMULATOR ? "-wipe-data -no-snapshot-load -no-boot-anim -no-audio -snapshot clean_boot " : "" ;
9294 logInfo ( "Change appium config to fullReset: false if no restart of the device needed!" ) ;
9395 }
9496
@@ -131,6 +133,10 @@ export class DeviceManager implements IDeviceManager {
131133 }
132134 }
133135
136+ public static async getDevices ( query : IDevice ) {
137+ return await DeviceController . getDevices ( query ) ;
138+ }
139+
134140 public async installApp ( args : INsCapabilities ) : Promise < any > {
135141 if ( args . isIOS ) {
136142 IOSController . installApp ( args . device , args . appiumCaps . app ) ;
@@ -149,7 +155,13 @@ export class DeviceManager implements IDeviceManager {
149155 }
150156
151157 public static async kill ( device : IDevice ) {
152- await DeviceController . kill ( device ) ;
158+ if ( device ) {
159+ await DeviceController . kill ( device ) ;
160+ }
161+ }
162+
163+ public static async getInstalledApps ( device : IDevice ) {
164+ return await DeviceController . getInstalledApplication ( device ) ;
153165 }
154166
155167 public static getDefaultDevice ( args : INsCapabilities , deviceName ?: string , token ?: string , type ?: DeviceType , platformVersion ?: number ) {
0 commit comments