UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

58 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_TIMEOUT_KEY = void 0; exports.requireArgs = requireArgs; exports.checkAppPresent = checkAppPresent; exports.normalizeCommandTimeouts = normalizeCommandTimeouts; const driver_1 = require("appium/driver"); const support_1 = require("appium/support"); const utils_1 = require("../../utils"); const logger_1 = require("../../logger"); exports.DEFAULT_TIMEOUT_KEY = 'default'; /** Assert the presence of particular keys in the given object. */ function requireArgs(argNames, opts = {}) { for (const argName of Array.isArray(argNames) ? argNames : [argNames]) { if (!Object.hasOwn(opts, argName)) { throw new driver_1.errors.InvalidArgumentError(`'${argName}' argument must be provided`); } } return opts; } /** Ensures application path exists before attempting installation. */ async function checkAppPresent(app) { logger_1.log.debug(`Checking whether app '${app}' is actually present on file system`); if (!(await support_1.fs.exists(app))) { throw logger_1.log.errorWithException(`Could not find app at '${app}'`); } logger_1.log.debug('App is present'); } /** Normalizes command timeout capability into a validated milliseconds map. */ function normalizeCommandTimeouts(value) { // The value is normalized already if (typeof value !== 'string') { return value; } let result = {}; // Use as default timeout for all commands if a single integer value is provided if (!isNaN(Number(value))) { result[exports.DEFAULT_TIMEOUT_KEY] = Number.parseInt(String(value), 10); return result; } // JSON object has been provided. Let's parse it try { result = JSON.parse(value); if (!(0, utils_1.isPlainObject)(result)) { throw new Error(); } } catch { throw logger_1.log.errorWithException(`"commandTimeouts" capability should be a valid JSON object. "${value}" was given instead`); } for (const [cmd, timeout] of Object.entries(result)) { if (!Number.isInteger(timeout) || timeout <= 0) { throw logger_1.log.errorWithException(`The timeout for "${cmd}" should be a valid natural number of milliseconds. "${timeout}" was given instead`); } } return result; } //# sourceMappingURL=validation.js.map