@@ -107,6 +107,11 @@ class AndroidDriver extends BaseDriver {
107
107
this . jwpProxyAvoid . push ( [ 'GET' , new RegExp ( '^/session/[^/]+/screenshot' ) ] ) ;
108
108
}
109
109
110
+ if ( this . opts . reboot ) {
111
+ this . setAvdFromCapabilities ( caps ) ;
112
+ this . addWipeDataToAvdArgs ( ) ;
113
+ }
114
+
110
115
// get device udid for this session
111
116
let { udid, emPort} = await helpers . getDeviceInfoFromCaps ( this . opts ) ;
112
117
this . opts . udid = udid ;
@@ -143,6 +148,29 @@ class AndroidDriver extends BaseDriver {
143
148
}
144
149
}
145
150
151
+ setAvdFromCapabilities ( caps ) {
152
+ if ( this . opts . avd ) {
153
+ log . info ( 'avd name defined, ignoring device name and platform version' ) ;
154
+ } else {
155
+ if ( ! caps . deviceName ) {
156
+ log . errorAndThrow ( 'avd or deviceName should be specified when reboot option is enables' ) ;
157
+ }
158
+ if ( ! caps . platformVersion ) {
159
+ log . errorAndThrow ( 'avd or platformVersion should be specified when reboot option is enabled' ) ;
160
+ }
161
+ let avdDevice = caps . deviceName . replace ( / [ ^ a - z A - Z 0 - 9 _ . ] / g, "-" ) ;
162
+ this . opts . avd = `${ avdDevice } __${ caps . platformVersion } ` ;
163
+ }
164
+ }
165
+
166
+ addWipeDataToAvdArgs ( ) {
167
+ if ( ! this . opts . avdArgs ) {
168
+ this . opts . avdArgs = '-wipe-data' ;
169
+ } else if ( this . opts . avdArgs . toLowerCase ( ) . indexOf ( "-wipe-data" ) === - 1 ) {
170
+ this . opts . avdArgs += ' -wipe-data' ;
171
+ }
172
+ }
173
+
146
174
get appOnDevice ( ) {
147
175
return this . helpers . isPackageOrBundle ( this . opts . app ) || ( ! this . opts . app &&
148
176
this . helpers . isPackageOrBundle ( this . opts . appPackage ) ) ;
@@ -312,6 +340,11 @@ class AndroidDriver extends BaseDriver {
312
340
await this . adb . uninstallApk ( this . opts . appPackage ) ;
313
341
}
314
342
await this . bootstrap . shutdown ( ) ;
343
+ if ( this . opts . reboot ) {
344
+ let avdName = this . opts . avd . replace ( '@' , '' ) ;
345
+ log . debug ( `closing emulator '${ avdName } '` ) ;
346
+ this . adb . killEmulator ( avdName ) ;
347
+ }
315
348
this . bootstrap = null ;
316
349
} else {
317
350
log . debug ( "Called deleteSession but bootstrap wasn't active" ) ;
0 commit comments