appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
112 lines • 4.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mobilePerformIoHidEvent = mobilePerformIoHidEvent;
exports.mobilePerformIndigoHidEvent = mobilePerformIndigoHidEvent;
const driver_1 = require("appium/driver");
const hid_indigo_client_1 = require("../device/hid-indigo-client");
const helpers_1 = require("./helpers");
const hid_event_1 = require("./hid-event");
/**
* Emulates triggering of the given low-level IO HID device event.
*
* Popular constants:
* - `kHIDPage_Consumer` = `0x0C`
* - `kHIDUsage_Csmr_VolumeIncrement` = `0xE9` (Volume Up)
* - `kHIDUsage_Csmr_VolumeDecrement` = `0xEA` (Volume Down)
* - `kHIDUsage_Csmr_Menu` = `0x40` (Home)
* - `kHIDUsage_Csmr_Power` = `0x30` (Power)
* - `kHIDUsage_Csmr_Snapshot` = `0x65` (Power + Home)
*
* @param page - The event page identifier
* @param usage - The event usage identifier (usages are defined per-page)
* @param durationSeconds - The event duration in float seconds (XCTest uses `0.005` for a single press event)
*/
async function mobilePerformIoHidEvent(page, usage, durationSeconds) {
if (!isHIDPageEvent(page)) {
throw new driver_1.errors.InvalidArgumentError(`'page' argument must be a valid HIDPageEvent identifier`);
}
if (!isHIDUsageEvent(usage)) {
throw new driver_1.errors.InvalidArgumentError(`'usage' must be a valid HIDUsageEvent identifier`);
}
const duration = parseFloat(String(durationSeconds));
if (Number.isNaN(duration)) {
throw new driver_1.errors.InvalidArgumentError(`'durationSeconds' argument must be a valid number`);
}
await this.proxyCommand('/wda/performIoHidEvent', 'POST', { page, usage, duration });
}
/**
* Emulates triggering of the given low-level IO HID device event
* via the HID Indigo RemoteXPC service.
*
* Requires **iOS/tvOS 26+**, real device, and a running RemoteXPC tunnel.
*
* @param name - The name of the button to press. Either this or both `page` and `usage` must be provided.
* @param page - The page of the button to press. Either this or `name` must be provided.
* @param usage - The usage of the button to press. Either this or `name` must be provided.
* @param durationSeconds - The duration of the button press in float seconds.
* @param pressCount - The number of times to press the button.
*/
async function mobilePerformIndigoHidEvent(name, page, usage, durationSeconds, pressCount) {
(0, helpers_1.requireRealDevice)(this, 'perform IO HID event with HID Indigo RemoteXPC service');
if (name === undefined && (page === undefined || usage === undefined)) {
throw new driver_1.errors.InvalidArgumentError(`Either 'name' or both 'page' and 'usage' must be provided`);
}
const getDuration = () => {
if (durationSeconds === undefined) {
return undefined;
}
const duration = parseFloat(String(durationSeconds));
if (Number.isNaN(duration)) {
throw new driver_1.errors.InvalidArgumentError(`'durationSeconds' argument must be a valid number`);
}
return duration;
};
const getPressCount = () => {
if (pressCount === undefined) {
return undefined;
}
const count = parseInt(String(pressCount), 10);
if (Number.isNaN(count)) {
throw new driver_1.errors.InvalidArgumentError(`'pressCount' argument must be a valid number`);
}
return count;
};
const hidIndigoClient = new hid_indigo_client_1.HidIndigoClient(this.device.udid, this.remoteXPCFacade);
if (name !== undefined) {
await hidIndigoClient.pressButtonByName(name, {
holdSeconds: getDuration(),
pressCount: getPressCount(),
});
}
else {
await hidIndigoClient.pressButtonByPageAndUsage(page, usage, {
holdSeconds: getDuration(),
pressCount: getPressCount(),
});
}
}
/**
* Type guard for {@linkcode HIDUsageEvent}
*/
function isHIDUsageEvent(value) {
if (typeof value === 'string') {
value = parseInt(value, 10);
}
if (Number.isNaN(value) || typeof value !== 'number') {
return false;
}
return value in hid_event_1.HIDUsageEvent;
}
/**
* Type guard for {@linkcode HIDPageEvent}
*/
function isHIDPageEvent(value) {
if (typeof value === 'string') {
value = parseInt(value, 10);
}
if (Number.isNaN(value) || typeof value !== 'number') {
return false;
}
return value in hid_event_1.HIDPageEvent;
}
//# sourceMappingURL=iohid.js.map