diff --git a/index.ts b/index.ts index 1b0143c..a23972d 100644 --- a/index.ts +++ b/index.ts @@ -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)); @@ -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; } diff --git a/lib/appium-driver.d.ts b/lib/appium-driver.d.ts index e043d05..4590c45 100644 --- a/lib/appium-driver.d.ts +++ b/lib/appium-driver.d.ts @@ -168,4 +168,5 @@ export declare class AppiumDriver { * @param waitForElement */ findElementByTextIfExists(text: string, match?: SearchOptions, waitForElement?: number): Promise; + setDontKeepActivities(value: boolean): Promise; } diff --git a/lib/appium-driver.ts b/lib/appium-driver.ts index 4125e88..4276699 100644 --- a/lib/appium-driver.ts +++ b/lib/appium-driver.ts @@ -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, @@ -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 { @@ -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; @@ -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 ... + } + } } \ No newline at end of file