Skip to content

Commit 6be8e06

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 5fcb520 commit 6be8e06

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/driver.js

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

110+
if (this.opts.reboot) {
111+
this.setAvdFromCapabilities(caps);
112+
this.addWipeDataToAvdArgs();
113+
}
114+
110115
// get device udid for this session
111116
let {udid, emPort} = await helpers.getDeviceInfoFromCaps(this.opts);
112117
this.opts.udid = udid;
@@ -143,6 +148,29 @@ class AndroidDriver extends BaseDriver {
143148
}
144149
}
145150

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-zA-Z0-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+
146174
get appOnDevice () {
147175
return this.helpers.isPackageOrBundle(this.opts.app) || (!this.opts.app &&
148176
this.helpers.isPackageOrBundle(this.opts.appPackage));
@@ -312,6 +340,11 @@ class AndroidDriver extends BaseDriver {
312340
await this.adb.uninstallApk(this.opts.appPackage);
313341
}
314342
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+
}
315348
this.bootstrap = null;
316349
} else {
317350
log.debug("Called deleteSession but bootstrap wasn't active");

0 commit comments

Comments
 (0)