UNPKG

appium-android-driver

Version:

Android UiAutomator and Chrome support for Appium

87 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SET_STYLUS_HANDWRITING_FEATURE = exports.GET_SERVER_LOGS_FEATURE = exports.ADB_LISTEN_ALL_NETWORK_FEATURE = exports.ADB_SHELL_FEATURE = void 0; exports.requireArgs = requireArgs; exports.parseArray = parseArray; exports.removeAllSessionWebSocketHandlers = removeAllSessionWebSocketHandlers; exports.nativeLogEntryToSeleniumEntry = nativeLogEntryToSeleniumEntry; exports.toLogRecord = toLogRecord; const driver_1 = require("appium/driver"); const support_1 = require("@appium/support"); exports.ADB_SHELL_FEATURE = 'adb_shell'; exports.ADB_LISTEN_ALL_NETWORK_FEATURE = 'adb_listen_all_network'; exports.GET_SERVER_LOGS_FEATURE = 'get_server_logs'; exports.SET_STYLUS_HANDWRITING_FEATURE = 'set_stylus_handwriting'; const COLOR_CODE_PATTERN = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex /** * Assert the presence of particular keys in the given object * * @param argNames one or more key names * @param opts the object to check * @returns the same given object */ function requireArgs(argNames, opts) { for (const argName of Array.isArray(argNames) ? argNames : [argNames]) { if (support_1.util.isPlainObject(opts) && !Object.hasOwn(opts, argName)) { throw new driver_1.errors.InvalidArgumentError(`'${argName}' argument must be provided`); } } return opts; } /** * * @param cap * @returns */ function parseArray(cap) { let parsedCaps; try { parsedCaps = JSON.parse(cap); } catch { } if (Array.isArray(parsedCaps)) { return parsedCaps; } else if (typeof cap === 'string') { return [cap]; } throw new Error(`must provide a string or JSON Array; received ${cap}`); } /** * @this AndroidDriver * @returns */ async function removeAllSessionWebSocketHandlers() { if (!this.sessionId || typeof this.server?.getWebSocketHandlers !== 'function') { return; } const activeHandlers = await this.server.getWebSocketHandlers(this.sessionId); for (const pathname of Object.keys(activeHandlers)) { await this.server.removeWebSocketHandler(pathname); } } /** * * @param x * @returns */ function nativeLogEntryToSeleniumEntry(x) { const msg = support_1.util.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`; return toLogRecord(x.timestamp ?? Date.now(), msg.replace(COLOR_CODE_PATTERN, '')); } /** * * @see {@link https://github.com/SeleniumHQ/selenium/blob/0d425676b3c9df261dd641917f867d4d5ce7774d/java/client/src/org/openqa/selenium/logging/LogEntry.java} * @param timestamp * @param message * @param level * @returns */ function toLogRecord(timestamp, message, level = 'ALL') { return { timestamp, level: level, message, }; } //# sourceMappingURL=utils.js.map