UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

44 lines 2.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mobileSendMemoryWarning = mobileSendMemoryWarning; const lodash_1 = __importDefault(require("lodash")); const driver_1 = require("appium/driver"); /** * Simulates Low Memory warning on the given application * * @since Xcode 15 * @param bundleId - The bundle identifier of the target app. The app must be running * @throws If the app is not running or is not installed */ async function mobileSendMemoryWarning(bundleId) { if (!this.isRealDevice()) { throw new Error('Memory warning simulation is only supported on real devices'); } const device = this.device; const appInfos = await device.devicectl.listApps(bundleId); if (lodash_1.default.isEmpty(appInfos)) { throw new driver_1.errors.InvalidArgumentError(`The application identified by ${bundleId} cannot be found on the device. Is it installed?`); } // This regexp tries to match the process name of the main bundle executable. // For example, if 'url' contains something like // `file:///private/var/containers/Bundle/Application/093ACA6D-8F0B-4601-87B9-4099E43A1A20/Target.app/` // and the following processes might be running: // `file:///private/var/containers/Bundle/Application/093ACA6D-8F0B-4601-87B9-4099E43A1A20/Target.app/Target` // `file:///private/var/containers/Bundle/Application/093ACA6D-8F0B-4601-87B9-4099E43A1A20/Target.app/PlugIns/WidgetExtension.appex/WidgetExtension` // then we only want to match the first one. // Unfortunately devicectl does not provide more info which would // allow to connect a bundle id to a process id. const pattern = new RegExp(`^${lodash_1.default.escapeRegExp(appInfos[0].url)}[^/]+$`); const pids = (await device.devicectl.listProcesses()) .filter(({ executable }) => pattern.test(executable)) .map(({ processIdentifier }) => processIdentifier); if (lodash_1.default.isEmpty(pids)) { throw new driver_1.errors.InvalidArgumentError(`The application identified by ${bundleId} must be running in order to simulate the Low Memory warning`); } this.log.info(`Emulating Low Memory warning for the process id ${pids[0]}, bundle id ${bundleId}`); await device.devicectl.sendMemoryWarning(pids[0]); } //# sourceMappingURL=memory.js.map