Skip to content

Commit f9a03d4

Browse files
committed
Honor reset without the app capability
Fixes appium#157
1 parent b085f08 commit f9a03d4

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/driver.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class AndroidDriver extends BaseDriver {
171171
// unlock the device
172172
await helpers.unlock(this.adb);
173173
// If the user sets autoLaunch to false, they are responsible for initAUT() and startAUT()
174-
if (!this.appOnDevice && this.opts.autoLaunch) {
174+
if (this.opts.autoLaunch) {
175175
// set up app under test
176176
await this.initAUT();
177177
}
@@ -225,14 +225,20 @@ class AndroidDriver extends BaseDriver {
225225
let launchInfo = await helpers.getLaunchInfo(this.adb, this.opts);
226226
Object.assign(this.opts, launchInfo);
227227
Object.assign(this.caps, launchInfo);
228-
if (!this.opts.skipUninstall) {
229-
await this.adb.uninstallApk(this.opts.appPackage);
230-
}
231228
// install app
232229
if (!this.opts.app) {
230+
if (this.opts.fullReset) {
231+
log.errorAndThrow('Full reset requires an app capability, use fastReset if app is not provided');
232+
}
233233
log.debug('No app capability. Assuming it is already on the device');
234+
if (this.opts.fastReset) {
235+
await helpers.resetApp(this.adb, this.opts.app, this.opts.appPackage, this.opts.fastReset);
236+
}
234237
return;
235238
}
239+
if (!this.opts.skipUninstall) {
240+
await this.adb.uninstallApk(this.opts.appPackage);
241+
}
236242
await helpers.installApkRemotely(this.adb, this.opts);
237243
this.apkStrings[this.opts.language] = await helpers.pushStrings(
238244
this.opts.language, this.adb, this.opts);

test/unit/commands/general-specs.js

+25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ describe('General', () => {
2626
await driver.installApp('non/existent/app.apk').should.be.rejectedWith(/Could not find/);
2727
});
2828
});
29+
describe('Run installed App', withMocks({helpers}, (mocks) => {
30+
it('should throw error if run with full reset', async () => {
31+
driver = new AndroidDriver();
32+
driver.opts = {appPackage: "app.package", appActivity: "act", fullReset: true};
33+
driver.caps = {};
34+
await driver.initAUT().should.be.rejectedWith(/Full reset requires an app capability/);
35+
});
36+
it('should reset if run with fast reset', async () => {
37+
driver = new AndroidDriver();
38+
driver.opts = {appPackage: "app.package", appActivity: "act", fullReset: false, fastReset: true};
39+
driver.caps = {};
40+
driver.adb = "mock_adb";
41+
mocks.helpers.expects("resetApp").withExactArgs("mock_adb", undefined, "app.package", true);
42+
await driver.initAUT();
43+
mocks.helpers.verify();
44+
});
45+
it('should keep data if run without reset', async () => {
46+
driver = new AndroidDriver();
47+
driver.opts = {appPackage: "app.package", appActivity: "act", fullReset: false, fastReset: false};
48+
driver.caps = {};
49+
mocks.helpers.expects("resetApp").never();
50+
await driver.initAUT();
51+
mocks.helpers.verify();
52+
});
53+
}));
2954
describe('getStrings', withMocks({helpers}, (mocks) => {
3055
it('should return app strings', async () => {
3156
driver = new AndroidDriver();

0 commit comments

Comments
 (0)