appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
88 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationClient = void 0;
const appium_ios_device_1 = require("appium-ios-device");
/**
* Unified Notification Proxy Client
*
* Provides a unified interface for notification proxy operations on iOS devices,
* automatically handling the differences between iOS < 18 (appium-ios-device)
* and iOS 18 and above (appium-ios-remotexpc NotificationProxyService).
*/
class NotificationClient {
service;
_isRemoteXPC;
log;
constructor(service, log, isRemoteXPC) {
this.service = service;
this.log = log;
this._isRemoteXPC = isRemoteXPC;
}
/**
* Check if this client is using RemoteXPC
*/
get isRemoteXPC() {
return this._isRemoteXPC;
}
/**
* Get service as RemoteXPC NotificationProxyService
*/
get remoteXPCNotificationProxy() {
return this.service;
}
/**
* Get service as iOS Device NotificationProxy
*/
get iosDeviceNotificationProxy() {
return this.service;
}
/**
* Create a notification client for device
*
* @param udid - Device UDID
* @param opts - Creation options
* @returns NotificationClient instance
*/
static async create(udid, opts) {
const { allowLegacyFallback = true, facade = null, logger } = opts;
const service = facade
? await facade.attemptService('notification proxy', (Services) => Services.startNotificationProxyService(udid))
: null;
if (service) {
return new NotificationClient(service, logger, true);
}
if (!allowLegacyFallback) {
throw new Error(`Notification proxy access via RemoteXPC is required for '${udid}', but it is unavailable.`);
}
// Fallback to appium-ios-device
const notificationProxy = await appium_ios_device_1.services.startNotificationProxyService(udid);
return new NotificationClient(notificationProxy, logger, false);
}
/**
* Observe a specific notification and wait for it
*
* @param notificationName - Name of the notification to observe
* @returns Promise that resolves when the notification is received
*/
async observeNotification(notificationName) {
if (this.isRemoteXPC) {
await this.remoteXPCNotificationProxy.observe(notificationName);
}
else {
// iOS Device: Use callback-based observation wrapped in a promise
return new Promise((resolve) => {
this.iosDeviceNotificationProxy.observeNotification(notificationName, {
notification: resolve,
});
});
}
}
/**
* Close the notification service connection
*/
async close() {
this.service.close();
}
}
exports.NotificationClient = NotificationClient;
//# sourceMappingURL=notification-client.js.map