Skip to content

Commit 5953a97

Browse files
fix: Use devicectl while listing available device udids (#2648)
1 parent ccf5ed6 commit 5953a97

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lib/real-device-management.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import {buildSafariPreferences} from './app-utils';
3-
import {utilities} from 'appium-ios-device';
3+
import { getConnectedDevices } from './real-device';
44

55
const DEFAULT_APP_INSTALLATION_TIMEOUT_MS = 8 * 60 * 1000;
66

@@ -114,11 +114,11 @@ export function applySafariStartupArgs() {
114114
*/
115115
export async function detectUdid() {
116116
this.log.debug('Auto-detecting real device udid...');
117-
const udids = await utilities.getConnectedDevices();
117+
const udids = await getConnectedDevices();
118118
if (_.isEmpty(udids)) {
119119
throw new Error('No real devices are connected to the host');
120120
}
121-
const udid = _.last(udids);
121+
const udid = udids[udids.length - 1];
122122
if (udids.length > 1) {
123123
this.log.info(`Multiple devices found: ${udids.join(', ')}`);
124124
this.log.info(`Choosing '${udid}'. Consider settings the 'udid' capability if another device must be selected`);

lib/real-device.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const INSTALLATION_STAGING_DIR = 'PublicStaging';
1616
* @returns {Promise<string[]>}
1717
*/
1818
export async function getConnectedDevices() {
19+
if (['yes', 'true', '1'].includes(_.toLower(process.env.APPIUM_XCUITEST_PREFER_DEVICECTL))) {
20+
return (await new Devicectl('').listDevices())
21+
.map(({hardwareProperties}) => hardwareProperties?.udid)
22+
.filter(Boolean);
23+
}
1924
return await utilities.getConnectedDevices();
2025
}
2126

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"lru-cache": "^11.1.0",
9999
"moment": "^2.29.4",
100100
"moment-timezone": "^0.x",
101-
"node-devicectl": "^1.0.1",
101+
"node-devicectl": "^1.1.0",
102102
"node-simctl": "^8.0.0",
103103
"portscanner": "^2.2.0",
104104
"semver": "^7.5.4",

0 commit comments

Comments
 (0)