appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
51 lines • 2.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.shutdownSimulator = void 0;
exports.killAllSimulators = killAllSimulators;
exports.deleteDeviceWithRetry = deleteDeviceWithRetry;
exports.cleanupSimulator = cleanupSimulator;
const lodash_1 = __importDefault(require("lodash"));
const node_simctl_1 = require("node-simctl");
const asyncbox_1 = require("asyncbox");
const appium_webdriveragent_1 = require("appium-webdriveragent");
const simulator_management_1 = require("../../../lib/device/simulator-management");
Object.defineProperty(exports, "shutdownSimulator", { enumerable: true, get: function () { return simulator_management_1.shutdownSimulator; } });
const appium_ios_simulator_1 = require("appium-ios-simulator");
async function killAllSimulators() {
const simctl = new node_simctl_1.Simctl();
const allDevices = lodash_1.default.flatMap(lodash_1.default.values(await simctl.getDevices()));
const bootedDevices = allDevices.filter((device) => device.state === 'Booted');
for (const { udid } of bootedDevices) {
// It is necessary to stop the corresponding xcodebuild process before killing
// the simulator, otherwise it will be automatically restarted
await (0, appium_webdriveragent_1.resetTestProcesses)(udid, true);
simctl.udid = udid;
await simctl.shutdownDevice();
}
await (0, appium_ios_simulator_1.killAllSimulators)();
}
/**
* @param {string} udid
*/
async function deleteDeviceWithRetry(udid) {
const simctl = new node_simctl_1.Simctl({ udid });
try {
await (0, asyncbox_1.retryInterval)(10, 1000, simctl.deleteDevice.bind(simctl));
}
catch { }
}
/**
* @param {import('appium-ios-simulator').Simulator} [sim]
*/
async function cleanupSimulator(sim) {
if (!sim) {
return;
}
await (0, appium_webdriveragent_1.resetTestProcesses)(sim.udid, true);
await sim.shutdown();
await deleteDeviceWithRetry(sim.udid);
}
//# sourceMappingURL=simulator.js.map