Skip to content

feat(android): add "Don't keep activities" functionality #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const nsCapabilities = new NsCapabilities();
const appiumServer = new AppiumServer(nsCapabilities);

let appiumDriver = null;

export async function startServer(port?: number, deviceManager?: IDeviceManager) {
await appiumServer.start(port || 8300, deviceManager);
appiumServer.server.on("exit", async (code) => await killProcesses(code));
Expand Down Expand Up @@ -58,6 +59,10 @@ export async function createDriver() {
await appiumDriver.init();
}

// Make sure to turn off "Don't keep activities"
// in case of previous execution failure.
await appiumDriver.setDontKeepActivities(false);

return appiumDriver;
}

Expand Down
1 change: 1 addition & 0 deletions lib/appium-driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ export declare class AppiumDriver {
* @param waitForElement
*/
findElementByTextIfExists(text: string, match?: SearchOptions, waitForElement?: number): Promise<UIElement>;
setDontKeepActivities(value: boolean): Promise<void>;
}
14 changes: 12 additions & 2 deletions lib/appium-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SearchOptions } from "./search-options";
import { UIElement } from "./ui-element";
import { Direction } from "./direction";
import { Locator } from "./locators";
import { Platform } from "mobile-devices-controller";

import {
addExt,
log,
Expand All @@ -24,12 +24,14 @@ import {
scroll,
findFreePort
} from "./utils";

import { INsCapabilities } from "./interfaces/ns-capabilities";
import { IRectangle } from "./interfaces/rectangle";
import { Point } from "./point";
import { ImageHelper } from "./image-helper";
import { ImageOptions } from "./image-options"
import { unlinkSync, writeFileSync } from "fs";
import { AndroidController } from "mobile-devices-controller";
import * as webdriverio from "webdriverio";

export class AppiumDriver {
Expand Down Expand Up @@ -462,7 +464,7 @@ export class AppiumDriver {
}

private static async applyAdditionalSettings(args) {
if (args.appiumCaps.platformName.toLowerCase() === Platform.IOS) {
if (args.isIOS) {
args.appiumCaps["useNewWDA"] = false;
args.appiumCaps["wdaStartupRetries"] = 5;
args.appiumCaps["shouldUseSingletonTestManager"] = false;
Expand Down Expand Up @@ -587,4 +589,12 @@ export class AppiumDriver {
const shouldMatch = match === SearchOptions.exact ? true : false;
return await this.findElementByXPathIfExists(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
}

public async setDontKeepActivities(value: boolean) {
if (this._args.isAndroid) {
AndroidController.setDontKeepActivities(value, this._args.device);
} else {
// Do nothing for iOS ...
}
}
}