UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

168 lines 7.08 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDriverInfo = exports.NATIVE_WIN = exports.UDID_AUTO = void 0; exports.removeAllSessionWebSocketHandlers = removeAllSessionWebSocketHandlers; exports.requireSimulator = requireSimulator; exports.requireRealDevice = requireRealDevice; exports.isTvOs = isTvOs; exports.normalizePlatformName = normalizePlatformName; exports.normalizePlatformVersion = normalizePlatformVersion; exports.shouldSetInitialSafariUrl = shouldSetInitialSafariUrl; exports.isIos17OrNewer = isIos17OrNewer; exports.isIos17OrNewerPlatform = isIos17OrNewerPlatform; exports.isIos18OrNewerPlatform = isIos18OrNewerPlatform; exports.isIos18OrNewer = isIos18OrNewer; const lodash_1 = __importDefault(require("lodash")); const support_1 = require("appium/support"); const semver = __importStar(require("semver")); const node_path_1 = __importDefault(require("node:path")); const desired_caps_1 = require("../desired-caps"); const MODULE_NAME = 'appium-xcuitest-driver'; exports.UDID_AUTO = 'auto'; exports.NATIVE_WIN = 'NATIVE_APP'; /** * Stops and removes all web socket handlers that are listening * in scope of the current session. */ async function removeAllSessionWebSocketHandlers() { if (!this.sessionId || !lodash_1.default.isFunction(this.server?.getWebSocketHandlers)) { return; } const activeHandlers = await this.server.getWebSocketHandlers(this.sessionId); for (const pathname of lodash_1.default.keys(activeHandlers)) { await this.server.removeWebSocketHandler(pathname); } } /** * Requires that the given driver is running on a Simulator and return * the simulator instance. */ function requireSimulator(driver, action) { if (!driver.isSimulator()) { throw new Error(`${lodash_1.default.upperFirst(action)} can only be performed on Simulator`); } return driver.device; } /** * Requires that the given driver is running on a real device and return * the real device instance. */ function requireRealDevice(driver, action) { if (!driver.isRealDevice()) { throw new Error(`${lodash_1.default.upperFirst(action)} can only be performed on a real device`); } return driver.device; } /** Check if platform name is the TV OS one. */ function isTvOs(platformName) { return lodash_1.default.toLower(platformName ?? '') === lodash_1.default.toLower(desired_caps_1.PLATFORM_NAME_TVOS); } /** Return normalized platform name. */ function normalizePlatformName(platformName) { return isTvOs(platformName) ? desired_caps_1.PLATFORM_NAME_TVOS : desired_caps_1.PLATFORM_NAME_IOS; } /** Normalizes platformVersion to a valid iOS version string. */ function normalizePlatformVersion(originalVersion) { const normalizedVersion = semver.coerce(originalVersion); if (!normalizedVersion) { throw new Error(`The platform version '${originalVersion}' should be a valid version number`); } return `${normalizedVersion.major}.${normalizedVersion.minor}`; } /** Whether the initial Safari URL should be pushed at session start. */ function shouldSetInitialSafariUrl(opts) { return (!(opts.safariInitialUrl === '' || (opts.noReset && lodash_1.default.isNil(opts.safariInitialUrl))) && !opts.initialDeeplinkUrl); } /** Version-gate helper for iOS 17+ capabilities. */ function isIos17OrNewer(opts) { return isIos17OrNewerPlatform(opts.platformVersion); } /** Platform-version predicate for iOS 17+. */ function isIos17OrNewerPlatform(platformVersion) { return !!platformVersion && support_1.util.compareVersions(platformVersion, '>=', '17.0'); } /** Platform-version predicate for iOS 18+. */ function isIos18OrNewerPlatform(platformVersion) { return !!platformVersion && support_1.util.compareVersions(platformVersion, '>=', '18.0'); } /** Version-gate helper for iOS 18+ capabilities. */ function isIos18OrNewer(opts) { return isIos18OrNewerPlatform(opts.platformVersion); } /** * Reads the content to the current module's package.json * * @returns The full path to module root * @throws If the current module's package.json cannot be determined */ const getModuleManifest = lodash_1.default.memoize(async function getModuleManifest() { // Start from the directory containing the compiled output (build/lib) or source (lib) // and walk up to find package.json let currentDir = node_path_1.default.resolve(__dirname, '..'); let isAtFsRoot = false; while (!isAtFsRoot) { const manifestPath = node_path_1.default.join(currentDir, 'package.json'); try { if (await support_1.fs.exists(manifestPath)) { const manifest = JSON.parse(await support_1.fs.readFile(manifestPath, 'utf8')); if (manifest.name === MODULE_NAME) { return manifest; } } } catch { } const parentDir = node_path_1.default.dirname(currentDir); isAtFsRoot = currentDir.length <= parentDir.length; currentDir = parentDir; } throw new Error(`Cannot find the package manifest of the ${MODULE_NAME} Node.js module`); }); /** Gets driver build/version metadata from package manifest. */ exports.getDriverInfo = lodash_1.default.memoize(async function getDriverInfo() { const [stat, manifest] = await Promise.all([ support_1.fs.stat(node_path_1.default.resolve(__dirname, '..')), getModuleManifest(), ]); return { built: stat.mtime.toString(), version: manifest.version, }; }); //# sourceMappingURL=driver.js.map