appium-ios-simulator 8.1.3 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/lib/extensions/settings.js +5 -5
- package/build/lib/extensions/settings.js.map +1 -1
- package/build/lib/simulator-xcode-14.d.ts +2 -0
- package/build/lib/simulator-xcode-14.d.ts.map +1 -1
- package/build/lib/simulator-xcode-14.js +16 -19
- package/build/lib/simulator-xcode-14.js.map +1 -1
- package/build/lib/simulator-xcode-15.d.ts.map +1 -1
- package/build/lib/simulator-xcode-15.js +2 -16
- package/build/lib/simulator-xcode-15.js.map +1 -1
- package/build/lib/simulator-xcode-27.d.ts +6 -0
- package/build/lib/simulator-xcode-27.d.ts.map +1 -0
- package/build/lib/simulator-xcode-27.js +13 -0
- package/build/lib/simulator-xcode-27.js.map +1 -0
- package/build/lib/simulator.d.ts.map +1 -1
- package/build/lib/simulator.js +9 -8
- package/build/lib/simulator.js.map +1 -1
- package/build/lib/utils/constants.d.ts +7 -0
- package/build/lib/utils/constants.d.ts.map +1 -0
- package/build/lib/utils/constants.js +10 -0
- package/build/lib/utils/constants.js.map +1 -0
- package/build/lib/{defaults-utils.d.ts → utils/defaults.d.ts} +1 -1
- package/build/lib/utils/defaults.d.ts.map +1 -0
- package/build/lib/{defaults-utils.js → utils/defaults.js} +2 -2
- package/build/lib/utils/defaults.js.map +1 -0
- package/build/lib/utils/devices.d.ts +13 -0
- package/build/lib/utils/devices.d.ts.map +1 -0
- package/build/lib/utils/devices.js +24 -0
- package/build/lib/utils/devices.js.map +1 -0
- package/build/lib/utils/get-devices.d.ts +7 -0
- package/build/lib/utils/get-devices.d.ts.map +1 -0
- package/build/lib/utils/get-devices.js +12 -0
- package/build/lib/utils/get-devices.js.map +1 -0
- package/build/lib/utils/index.d.ts +9 -0
- package/build/lib/utils/index.d.ts.map +1 -0
- package/build/lib/utils/index.js +29 -0
- package/build/lib/utils/index.js.map +1 -0
- package/build/lib/utils/lifecycle.d.ts +6 -0
- package/build/lib/utils/lifecycle.d.ts.map +1 -0
- package/build/lib/utils/lifecycle.js +66 -0
- package/build/lib/utils/lifecycle.js.map +1 -0
- package/build/lib/utils/process.d.ts +11 -0
- package/build/lib/utils/process.d.ts.map +1 -0
- package/build/lib/utils/process.js +36 -0
- package/build/lib/utils/process.js.map +1 -0
- package/build/lib/utils/types.d.ts +4 -0
- package/build/lib/utils/types.d.ts.map +1 -0
- package/build/lib/utils/types.js +3 -0
- package/build/lib/utils/types.js.map +1 -0
- package/build/lib/utils/xcode.d.ts +27 -0
- package/build/lib/utils/xcode.d.ts.map +1 -0
- package/build/lib/utils/xcode.js +80 -0
- package/build/lib/utils/xcode.js.map +1 -0
- package/lib/extensions/settings.ts +1 -1
- package/lib/simulator-xcode-14.ts +23 -19
- package/lib/simulator-xcode-15.ts +4 -15
- package/lib/simulator-xcode-27.ts +9 -0
- package/lib/simulator.ts +14 -10
- package/lib/utils/constants.ts +6 -0
- package/lib/{defaults-utils.ts → utils/defaults.ts} +1 -1
- package/lib/utils/devices.ts +25 -0
- package/lib/utils/get-devices.ts +10 -0
- package/lib/utils/index.ts +20 -0
- package/lib/utils/lifecycle.ts +78 -0
- package/lib/utils/process.ts +31 -0
- package/lib/utils/types.ts +3 -0
- package/lib/utils/xcode.ts +86 -0
- package/package.json +1 -1
- package/build/lib/defaults-utils.d.ts.map +0 -1
- package/build/lib/defaults-utils.js.map +0 -1
- package/build/lib/utils.d.ts +0 -44
- package/build/lib/utils.d.ts.map +0 -1
- package/build/lib/utils.js +0 -211
- package/build/lib/utils.js.map +0 -1
- package/lib/utils.ts +0 -189
package/lib/utils.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import {log} from './logger';
|
|
2
|
-
import {exec} from 'teen_process';
|
|
3
|
-
import {waitForCondition} from 'asyncbox';
|
|
4
|
-
import {getVersion} from 'appium-xcode';
|
|
5
|
-
import type {XcodeVersion} from 'appium-xcode';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import {Simctl} from 'node-simctl';
|
|
8
|
-
import type {StringRecord} from '@appium/types';
|
|
9
|
-
// it's a hack needed to stub getDevices in tests
|
|
10
|
-
import * as utilsModule from './utils';
|
|
11
|
-
|
|
12
|
-
const DEFAULT_SIM_SHUTDOWN_TIMEOUT_MS = 30000;
|
|
13
|
-
export const SAFARI_STARTUP_TIMEOUT_MS = 25 * 1000;
|
|
14
|
-
export const MOBILE_SAFARI_BUNDLE_ID = 'com.apple.mobilesafari';
|
|
15
|
-
export const SIMULATOR_APP_NAME = 'Simulator.app';
|
|
16
|
-
export const MIN_SUPPORTED_XCODE_VERSION = 14;
|
|
17
|
-
|
|
18
|
-
export interface SimulatorInfoOptions {
|
|
19
|
-
devicesSetPath?: string | null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @param timeout - Timeout in milliseconds (default: DEFAULT_SIM_SHUTDOWN_TIMEOUT_MS).
|
|
24
|
-
* @returns Promise that resolves when all simulators are killed.
|
|
25
|
-
*/
|
|
26
|
-
export async function killAllSimulators(
|
|
27
|
-
timeout: number = DEFAULT_SIM_SHUTDOWN_TIMEOUT_MS,
|
|
28
|
-
): Promise<void> {
|
|
29
|
-
log.debug('Killing all iOS Simulators');
|
|
30
|
-
const xcodeVersion = await getVersion(true);
|
|
31
|
-
if (typeof xcodeVersion === 'string') {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const appName = path.parse(SIMULATOR_APP_NAME).name;
|
|
35
|
-
const version = xcodeVersion as XcodeVersion;
|
|
36
|
-
|
|
37
|
-
// later versions are slower to close
|
|
38
|
-
timeout = timeout * (version.major >= 8 ? 2 : 1);
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
await exec('xcrun', ['simctl', 'shutdown', version.major > 8 ? 'all' : 'booted'], {timeout});
|
|
42
|
-
} catch {}
|
|
43
|
-
|
|
44
|
-
const pids: string[] = [];
|
|
45
|
-
try {
|
|
46
|
-
const {stdout} = await exec('pgrep', ['-f', `${appName}.app/Contents/MacOS/`]);
|
|
47
|
-
if (stdout.trim()) {
|
|
48
|
-
pids.push(...stdout.trim().split(/\s+/));
|
|
49
|
-
}
|
|
50
|
-
} catch (e: any) {
|
|
51
|
-
if (e.code === 1) {
|
|
52
|
-
log.debug(`${appName} is not running. Continuing...`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (pids.length === 0) {
|
|
56
|
-
log.warn(
|
|
57
|
-
`pgrep error ${e.code} while detecting whether ${appName} is running. Trying to kill anyway.`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (pids.length > 0) {
|
|
62
|
-
log.debug(`Killing processes: ${pids.join(', ')}`);
|
|
63
|
-
try {
|
|
64
|
-
await exec('kill', ['-9', ...pids.map((pid) => `${pid}`)]);
|
|
65
|
-
} catch {}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
log.debug(`Using pkill to kill application: ${appName}`);
|
|
69
|
-
try {
|
|
70
|
-
await pkill(appName, true);
|
|
71
|
-
} catch {}
|
|
72
|
-
|
|
73
|
-
// wait for all the devices to be shutdown before Continuing
|
|
74
|
-
// but only print out the failed ones when they are actually fully failed
|
|
75
|
-
let remainingDevices: string[] = [];
|
|
76
|
-
async function allSimsAreDown(): Promise<boolean> {
|
|
77
|
-
remainingDevices = [];
|
|
78
|
-
const devicesRecord = await utilsModule.getDevices();
|
|
79
|
-
const devices = Object.values(devicesRecord).flat();
|
|
80
|
-
return devices.every((sim: any) => {
|
|
81
|
-
const state = sim.state.toLowerCase();
|
|
82
|
-
const done = ['shutdown', 'unavailable', 'disconnected'].includes(state);
|
|
83
|
-
if (!done) {
|
|
84
|
-
remainingDevices.push(
|
|
85
|
-
`${sim.name} (${sim.sdk}, udid: ${sim.udid}) is still in state '${state}'`,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return done;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
await waitForCondition(allSimsAreDown, {
|
|
93
|
-
waitMs: timeout,
|
|
94
|
-
intervalMs: 200,
|
|
95
|
-
});
|
|
96
|
-
} catch (err) {
|
|
97
|
-
if (remainingDevices.length > 0) {
|
|
98
|
-
log.warn(`The following devices are still not in the correct state after ${timeout} ms:`);
|
|
99
|
-
for (const device of remainingDevices) {
|
|
100
|
-
log.warn(` ${device}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
throw err;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @param udid - The simulator UDID.
|
|
109
|
-
* @param opts - Options including devicesSetPath.
|
|
110
|
-
* @returns Promise that resolves to simulator info or undefined if not found.
|
|
111
|
-
*/
|
|
112
|
-
export async function getSimulatorInfo(
|
|
113
|
-
udid: string,
|
|
114
|
-
opts: SimulatorInfoOptions = {},
|
|
115
|
-
): Promise<any> {
|
|
116
|
-
const {devicesSetPath} = opts;
|
|
117
|
-
// see the README for github.com/appium/node-simctl for example output of getDevices()
|
|
118
|
-
const devices = Object.values(await utilsModule.getDevices({devicesSetPath})).flat();
|
|
119
|
-
return devices.find((sim: any) => sim.udid === udid);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @param udid - The simulator UDID.
|
|
124
|
-
* @returns Promise that resolves to true if simulator exists, false otherwise.
|
|
125
|
-
*/
|
|
126
|
-
export async function simExists(udid: string): Promise<boolean> {
|
|
127
|
-
return !!(await getSimulatorInfo(udid));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @returns Promise that resolves to the developer root path.
|
|
132
|
-
*/
|
|
133
|
-
export async function getDeveloperRoot(): Promise<string> {
|
|
134
|
-
const {stdout} = await exec('xcode-select', ['-p']);
|
|
135
|
-
return stdout.trim();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Asserts that the Xcode version meets the minimum supported version requirement.
|
|
140
|
-
*
|
|
141
|
-
* @template V - The Xcode version type.
|
|
142
|
-
* @param xcodeVersion - The Xcode version to check.
|
|
143
|
-
* @returns The same Xcode version if it meets the requirement.
|
|
144
|
-
* @throws {Error} If the Xcode version is below the minimum supported version.
|
|
145
|
-
*/
|
|
146
|
-
export function assertXcodeVersion<V extends XcodeVersion>(xcodeVersion: V): V {
|
|
147
|
-
if (xcodeVersion.major < MIN_SUPPORTED_XCODE_VERSION) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
`Tried to use an iOS simulator with xcode version ${xcodeVersion.versionString} but only Xcode version ` +
|
|
150
|
-
`${MIN_SUPPORTED_XCODE_VERSION} and up are supported`,
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
return xcodeVersion;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @param simctlOpts - Optional simctl options
|
|
158
|
-
* @returns Promise that resolves to a record of devices grouped by SDK version
|
|
159
|
-
*/
|
|
160
|
-
export async function getDevices(simctlOpts?: StringRecord): Promise<Record<string, any[]>> {
|
|
161
|
-
return await new Simctl(simctlOpts).getDevices();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @param appName - The application name to kill.
|
|
166
|
-
* @param forceKill - Whether to force kill the process.
|
|
167
|
-
* @returns Promise that resolves to 0 on success.
|
|
168
|
-
*/
|
|
169
|
-
async function pkill(appName: string, forceKill: boolean = false): Promise<number> {
|
|
170
|
-
const args = forceKill ? ['-9'] : [];
|
|
171
|
-
args.push('-x', appName);
|
|
172
|
-
try {
|
|
173
|
-
await exec('pkill', args);
|
|
174
|
-
return 0;
|
|
175
|
-
} catch (err: any) {
|
|
176
|
-
// pgrep/pkill exit codes:
|
|
177
|
-
// 0 One or more processes were matched.
|
|
178
|
-
// 1 No processes were matched.
|
|
179
|
-
// 2 Invalid options were specified on the command line.
|
|
180
|
-
// 3 An internal error occurred.
|
|
181
|
-
if (err.code !== undefined) {
|
|
182
|
-
throw new Error(`Cannot forcefully terminate ${appName}. pkill error code: ${err.code}`, {
|
|
183
|
-
cause: err,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
log.error(`Received unexpected error while trying to kill ${appName}: ${err.message}`);
|
|
187
|
-
throw err;
|
|
188
|
-
}
|
|
189
|
-
}
|