Skip to content

Commit be8b47d

Browse files
committed
support reboot parameter for android
If reboot option activated, it will always wipe data of emulator on start, and close emulator at the end, It also use device name and platform version to create avd name, if it is not defined.
1 parent 5a3656b commit be8b47d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/driver.js

+24
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ class AndroidDriver extends BaseDriver {
107107
this.jwpProxyAvoid.push(['GET', new RegExp('^/session/[^/]+/screenshot')]);
108108
}
109109

110+
if (this.opts.reboot) {
111+
if (this.opts.avd) {
112+
log.info('avd name defined, ignoring device name and platform version');
113+
} else {
114+
if (!caps.deviceName) {
115+
log.errorAndThrow('avd or deviceName should be specified when reboot option is enables');
116+
}
117+
if (!caps.platformVersion) {
118+
log.errorAndThrow('avd or platformVersion should be specified when reboot option is enables');
119+
}
120+
let avdDevice = caps.deviceName.replace(/[^a-zA-Z0-9_.]/g, "-");
121+
this.opts.avd = `${avdDevice}__${caps.platformVersion}`;
122+
}
123+
if (!this.opts.avdArgs) {
124+
this.opts.avdArgs = '-wipe-data';
125+
} else if (this.opts.avdArgs.toLowerCase().indexOf("-wipe-data") === -1) {
126+
this.opts.avdArgs += ' -wipe-data';
127+
}
128+
}
110129
// get device udid for this session
111130
let {udid, emPort} = await helpers.getDeviceInfoFromCaps(this.opts);
112131
this.opts.udid = udid;
@@ -312,6 +331,11 @@ class AndroidDriver extends BaseDriver {
312331
await this.adb.uninstallApk(this.opts.appPackage);
313332
}
314333
await this.bootstrap.shutdown();
334+
if (this.opts.reboot) {
335+
let avdName = this.opts.avd.replace('@', '');
336+
log.debug(`closing emulator '${avdName}'`);
337+
this.adb.killEmulator(avdName);
338+
}
315339
this.bootstrap = null;
316340
} else {
317341
log.debug("Called deleteSession but bootstrap wasn't active");

0 commit comments

Comments
 (0)