diff --git a/lib/real-device-management.js b/lib/real-device-management.js index 3720b0faf..8a0a67493 100644 --- a/lib/real-device-management.js +++ b/lib/real-device-management.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import {buildSafariPreferences} from './app-utils'; -import {utilities} from 'appium-ios-device'; +import { getConnectedDevices } from './real-device'; const DEFAULT_APP_INSTALLATION_TIMEOUT_MS = 8 * 60 * 1000; @@ -114,11 +114,11 @@ export function applySafariStartupArgs() { */ export async function detectUdid() { this.log.debug('Auto-detecting real device udid...'); - const udids = await utilities.getConnectedDevices(); + const udids = await getConnectedDevices(); if (_.isEmpty(udids)) { throw new Error('No real devices are connected to the host'); } - const udid = _.last(udids); + const udid = udids[udids.length - 1]; if (udids.length > 1) { this.log.info(`Multiple devices found: ${udids.join(', ')}`); this.log.info(`Choosing '${udid}'. Consider settings the 'udid' capability if another device must be selected`); diff --git a/lib/real-device.js b/lib/real-device.js index 446bc5aa3..eb103d69f 100644 --- a/lib/real-device.js +++ b/lib/real-device.js @@ -16,6 +16,11 @@ const INSTALLATION_STAGING_DIR = 'PublicStaging'; * @returns {Promise} */ export async function getConnectedDevices() { + if (['yes', 'true', '1'].includes(_.toLower(process.env.APPIUM_XCUITEST_PREFER_DEVICECTL))) { + return (await new Devicectl('').listDevices()) + .map(({hardwareProperties}) => hardwareProperties?.udid) + .filter(Boolean); + } return await utilities.getConnectedDevices(); } diff --git a/package.json b/package.json index d72368d6e..7ac5bc89d 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "lru-cache": "^11.1.0", "moment": "^2.29.4", "moment-timezone": "^0.x", - "node-devicectl": "^1.0.1", + "node-devicectl": "^1.1.0", "node-simctl": "^8.0.0", "portscanner": "^2.2.0", "semver": "^7.5.4",