UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

82 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.XctestAttachmentDeletionClient = void 0; const remotexpc_utils_1 = require("./remotexpc-utils"); const utils_1 = require("../utils"); const REMOTEXPC_UPGRADE_HINT = 'Upgrade appium-ios-remotexpc to a version that exports XCTestAttachment ' + '(XCTest screen recording attachment deletion on real devices).'; /** * Deletes XCTest screen-recording attachments on a real device via appium-ios-remotexpc * (testmanagerd). Use {@link isDeletionAvailable} before start; {@link create} returns a client * ready to delete (or throws if deletion cannot run). */ class XctestAttachmentDeletionClient { udid; XCTestAttachment; constructor(udid, XCTestAttachment) { this.udid = udid; this.XCTestAttachment = XCTestAttachment; } /** * Whether attachment deletion can run: **iOS 18+**, **appium-ios-remotexpc** loadable, and * **XCTestAttachment** exported (new enough package). * * @param remotexpcModule - optional pre-loaded module (for unit tests) * @param log - if set, warns when the package is present but too old (no **XCTestAttachment** export) */ static async isDeletionAvailable(udid, platformVersion, remotexpcModule, log) { if (!udid?.trim() || !(0, utils_1.isIos18OrNewerPlatform)(platformVersion)) { return false; } let mod = remotexpcModule; if (mod === undefined) { mod = (await (0, remotexpc_utils_1.tryGetRemoteXPCModule)()); if (!mod) { return false; } } if (typeof mod?.XCTestAttachment === 'function') { return true; } if (mod && log) { log.warn(REMOTEXPC_UPGRADE_HINT); } return false; } /** * @param remotexpcModule - optional pre-loaded module (for unit tests) * @throws {Error} If real-device XCTest attachment deletion is not supported */ static async create(udid, platformVersion, remotexpcModule) { if (!udid?.trim()) { throw new Error('A device UDID is required for XCTest screen recording on a real device so attachments can be removed after stop.'); } if (!(0, utils_1.isIos18OrNewerPlatform)(platformVersion)) { throw new Error('XCTest screen recording on a real device requires iOS 18 or newer. ' + 'The driver removes recordings from the device after stop using appium-ios-remotexpc, which is only supported on iOS 18+.'); } let mod = remotexpcModule; if (mod === undefined) { mod = (await (0, remotexpc_utils_1.tryGetRemoteXPCModule)()); if (!mod) { throw new Error('appium-ios-remotexpc must be installed to use XCTest screen recording on a real device. ' + 'It is used to delete screen-recording attachments after stop.'); } } const XCTestAttachment = mod?.XCTestAttachment; if (!mod || typeof XCTestAttachment !== 'function') { throw new Error('The installed appium-ios-remotexpc package must export XCTestAttachment for real-device XCTest screen recording. ' + REMOTEXPC_UPGRADE_HINT); } return new XctestAttachmentDeletionClient(udid.trim(), XCTestAttachment); } async deleteAttachmentsByUuid(uuids) { if (!uuids.length) { return; } const attachment = new this.XCTestAttachment(this.udid); await attachment.delete(uuids); } } exports.XctestAttachmentDeletionClient = XctestAttachmentDeletionClient; //# sourceMappingURL=xctest-attachment-deletion-client.js.map