Skip to content

Commit 21ecadc

Browse files
author
Vasil Chimev
authored
feat(android): add "Don't keep activities" functionality (#94)
* feat(android): add "Don't keep activities" functionality This allows you to turn on/off "Don't keep activities" setting in the Developer options for Android. * refactor: move setDontKeepActivities to driver * refactor: turn off "Don't keep activities" prior execution This is in case of previous execution failure which could not turn off the setting. * refactor: applyAdditionalSettings method
1 parent d40d454 commit 21ecadc

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const nsCapabilities = new NsCapabilities();
2121
const appiumServer = new AppiumServer(nsCapabilities);
2222

2323
let appiumDriver = null;
24+
2425
export async function startServer(port?: number, deviceManager?: IDeviceManager) {
2526
await appiumServer.start(port || 8300, deviceManager);
2627
appiumServer.server.on("exit", async (code) => await killProcesses(code));
@@ -58,6 +59,10 @@ export async function createDriver() {
5859
await appiumDriver.init();
5960
}
6061

62+
// Make sure to turn off "Don't keep activities"
63+
// in case of previous execution failure.
64+
await appiumDriver.setDontKeepActivities(false);
65+
6166
return appiumDriver;
6267
}
6368

lib/appium-driver.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,5 @@ export declare class AppiumDriver {
168168
* @param waitForElement
169169
*/
170170
findElementByTextIfExists(text: string, match?: SearchOptions, waitForElement?: number): Promise<UIElement>;
171+
setDontKeepActivities(value: boolean): Promise<void>;
171172
}

lib/appium-driver.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SearchOptions } from "./search-options";
1010
import { UIElement } from "./ui-element";
1111
import { Direction } from "./direction";
1212
import { Locator } from "./locators";
13-
import { Platform } from "mobile-devices-controller";
13+
1414
import {
1515
addExt,
1616
log,
@@ -24,12 +24,14 @@ import {
2424
scroll,
2525
findFreePort
2626
} from "./utils";
27+
2728
import { INsCapabilities } from "./interfaces/ns-capabilities";
2829
import { IRectangle } from "./interfaces/rectangle";
2930
import { Point } from "./point";
3031
import { ImageHelper } from "./image-helper";
3132
import { ImageOptions } from "./image-options"
3233
import { unlinkSync, writeFileSync } from "fs";
34+
import { AndroidController } from "mobile-devices-controller";
3335
import * as webdriverio from "webdriverio";
3436

3537
export class AppiumDriver {
@@ -462,7 +464,7 @@ export class AppiumDriver {
462464
}
463465

464466
private static async applyAdditionalSettings(args) {
465-
if (args.appiumCaps.platformName.toLowerCase() === Platform.IOS) {
467+
if (args.isIOS) {
466468
args.appiumCaps["useNewWDA"] = false;
467469
args.appiumCaps["wdaStartupRetries"] = 5;
468470
args.appiumCaps["shouldUseSingletonTestManager"] = false;
@@ -587,4 +589,12 @@ export class AppiumDriver {
587589
const shouldMatch = match === SearchOptions.exact ? true : false;
588590
return await this.findElementByXPathIfExists(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
589591
}
592+
593+
public async setDontKeepActivities(value: boolean) {
594+
if (this._args.isAndroid) {
595+
AndroidController.setDontKeepActivities(value, this._args.device);
596+
} else {
597+
// Do nothing for iOS ...
598+
}
599+
}
590600
}

0 commit comments

Comments
 (0)