appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
85 lines • 2.93 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IOSDeviceLog = void 0;
const appium_ios_device_1 = require("appium-ios-device");
const line_consuming_log_1 = require("./line-consuming-log");
const remotexpc_utils_1 = require("../remotexpc-utils");
class IOSDeviceLog extends line_consuming_log_1.LineConsumingLog {
udid;
showLogs;
useRemoteXPC;
// Legacy service (appium-ios-device)
legacyService = null;
// RemoteXPC syslog service
syslogService = null;
constructor(opts) {
super({ log: opts.log });
this.udid = opts.udid;
this.showLogs = !!opts.showLogs;
this.useRemoteXPC = opts.useRemoteXPC ?? false;
}
get isCapturing() {
return !!this.syslogService || !!this.legacyService;
}
async startCapture() {
if (this.isCapturing) {
return;
}
if (this.useRemoteXPC) {
try {
await this.startRemoteXPCCapture();
this.log.info('Starting RemoteXPC syslog capture');
return;
}
catch (err) {
this.log.warn(`RemoteXPC syslog failed, falling back to legacy: ${err.message}`);
await this.stopRemoteXPCCapture();
}
}
await this.startLegacyCapture();
}
async stopCapture() {
await this.stopRemoteXPCCapture();
await this.stopLegacyCapture();
}
async startLegacyCapture() {
this.legacyService = await appium_ios_device_1.services.startSyslogService(this.udid);
this.legacyService.start(this.onLog.bind(this));
}
async stopLegacyCapture() {
if (!this.legacyService) {
return;
}
this.legacyService.close();
this.legacyService = null;
}
async startRemoteXPCCapture() {
const Services = await (0, remotexpc_utils_1.getRemoteXPCServices)();
const { syslogService, serviceDescriptor } = await Services.startSyslogTextService(this.udid);
this.syslogService = syslogService;
syslogService.on('message', this.onLog.bind(this));
syslogService.on('error', (err) => {
this.log.warn(`Syslog RemoteXPC error: ${err.message}`);
});
await syslogService.start(serviceDescriptor, { addPacketConsumer: () => { }, removePacketConsumer: () => { } }, { pid: -1, textMode: true });
}
async stopRemoteXPCCapture() {
if (!this.syslogService) {
return;
}
try {
await this.syslogService.stop();
}
catch { }
this.syslogService = null;
}
onLog(logLine) {
this.broadcast(logLine);
if (this.showLogs) {
this.log.info(`[IOS_SYSLOG_ROW] ${logLine}`);
}
}
}
exports.IOSDeviceLog = IOSDeviceLog;
exports.default = IOSDeviceLog;
//# sourceMappingURL=ios-device-log.js.map