appium-xcuitest-driver 10.8.3 → 10.9.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 +12 -0
- package/build/lib/app-utils.d.ts +2 -2
- package/build/lib/app-utils.d.ts.map +1 -1
- package/build/lib/app-utils.js +4 -1
- package/build/lib/app-utils.js.map +1 -1
- package/build/lib/commands/app-management.js +2 -2
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/appearance.js +2 -2
- package/build/lib/commands/appearance.js.map +1 -1
- package/build/lib/commands/biometric.js +3 -3
- package/build/lib/commands/biometric.js.map +1 -1
- package/build/lib/commands/certificate.d.ts.map +1 -1
- package/build/lib/commands/certificate.js +9 -3
- package/build/lib/commands/certificate.js.map +1 -1
- package/build/lib/commands/context.d.ts +5 -5
- package/build/lib/commands/context.d.ts.map +1 -1
- package/build/lib/commands/context.js +6 -6
- package/build/lib/commands/context.js.map +1 -1
- package/build/lib/commands/file-movement.d.ts.map +1 -1
- package/build/lib/commands/file-movement.js +7 -7
- package/build/lib/commands/file-movement.js.map +1 -1
- package/build/lib/commands/general.js +1 -1
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/gesture.js +1 -1
- package/build/lib/commands/gesture.js.map +1 -1
- package/build/lib/commands/keychains.js +1 -1
- package/build/lib/commands/keychains.js.map +1 -1
- package/build/lib/commands/localization.js +1 -1
- package/build/lib/commands/localization.js.map +1 -1
- package/build/lib/commands/location.js +1 -1
- package/build/lib/commands/location.js.map +1 -1
- package/build/lib/commands/log.js +7 -7
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/memory.js +1 -1
- package/build/lib/commands/memory.js.map +1 -1
- package/build/lib/commands/notifications.js +1 -1
- package/build/lib/commands/notifications.js.map +1 -1
- package/build/lib/commands/pasteboard.js +2 -2
- package/build/lib/commands/pasteboard.js.map +1 -1
- package/build/lib/commands/pcap.js +1 -1
- package/build/lib/commands/pcap.js.map +1 -1
- package/build/lib/commands/performance.d.ts.map +1 -1
- package/build/lib/commands/performance.js +13 -4
- package/build/lib/commands/performance.js.map +1 -1
- package/build/lib/commands/permissions.js +2 -2
- package/build/lib/commands/permissions.js.map +1 -1
- package/build/lib/commands/proxy-helper.d.ts.map +1 -1
- package/build/lib/commands/proxy-helper.js +0 -3
- package/build/lib/commands/proxy-helper.js.map +1 -1
- package/build/lib/commands/screenshots.js +1 -1
- package/build/lib/commands/screenshots.js.map +1 -1
- package/build/lib/commands/simctl.d.ts +1 -1
- package/build/lib/commands/simctl.d.ts.map +1 -1
- package/build/lib/commands/simctl.js +1 -1
- package/build/lib/commands/simctl.js.map +1 -1
- package/build/lib/commands/web.js +1 -1
- package/build/lib/commands/web.js.map +1 -1
- package/build/lib/commands/xctest-record-screen.js +2 -2
- package/build/lib/commands/xctest-record-screen.js.map +1 -1
- package/build/lib/desired-caps.d.ts +383 -507
- package/build/lib/desired-caps.d.ts.map +1 -1
- package/build/lib/desired-caps.js +6 -10
- package/build/lib/desired-caps.js.map +1 -1
- package/build/lib/device/clients/base-device-client.d.ts.map +1 -0
- package/build/lib/device/clients/base-device-client.js.map +1 -0
- package/build/lib/{real-device-clients → device/clients}/py-ios-device-client.d.ts +1 -1
- package/build/lib/device/clients/py-ios-device-client.d.ts.map +1 -0
- package/build/lib/device/clients/py-ios-device-client.js.map +1 -0
- package/build/lib/device/device-connections-factory.d.ts +18 -0
- package/build/lib/device/device-connections-factory.d.ts.map +1 -0
- package/build/lib/{device-connections-factory.js → device/device-connections-factory.js} +57 -41
- package/build/lib/device/device-connections-factory.js.map +1 -0
- package/build/lib/{device-log → device/log}/helpers.d.ts +1 -1
- package/build/lib/device/log/helpers.d.ts.map +1 -0
- package/build/lib/device/log/helpers.js.map +1 -0
- package/build/lib/{device-log → device/log}/ios-crash-log.d.ts +1 -1
- package/build/lib/device/log/ios-crash-log.d.ts.map +1 -0
- package/build/lib/{device-log → device/log}/ios-crash-log.js +1 -1
- package/build/lib/device/log/ios-crash-log.js.map +1 -0
- package/build/lib/device/log/ios-device-log.d.ts.map +1 -0
- package/build/lib/device/log/ios-device-log.js.map +1 -0
- package/build/lib/{device-log → device/log}/ios-log.d.ts +1 -1
- package/build/lib/device/log/ios-log.d.ts.map +1 -0
- package/build/lib/device/log/ios-log.js.map +1 -0
- package/build/lib/device/log/ios-performance-log.d.ts.map +1 -0
- package/build/lib/device/log/ios-performance-log.js.map +1 -0
- package/build/lib/device/log/ios-simulator-log.d.ts.map +1 -0
- package/build/lib/device/log/ios-simulator-log.js.map +1 -0
- package/build/lib/{device-log → device/log}/line-consuming-log.d.ts +1 -1
- package/build/lib/device/log/line-consuming-log.d.ts.map +1 -0
- package/build/lib/device/log/line-consuming-log.js.map +1 -0
- package/build/lib/{device-log → device/log}/safari-console-log.d.ts +1 -1
- package/build/lib/device/log/safari-console-log.d.ts.map +1 -0
- package/build/lib/device/log/safari-console-log.js.map +1 -0
- package/build/lib/device/log/safari-network-log.d.ts.map +1 -0
- package/build/lib/device/log/safari-network-log.js.map +1 -0
- package/build/lib/device/real-device-management.d.ts +146 -0
- package/build/lib/device/real-device-management.d.ts.map +1 -0
- package/build/lib/device/real-device-management.js +728 -0
- package/build/lib/device/real-device-management.js.map +1 -0
- package/build/lib/device/simulator-management.d.ts +65 -0
- package/build/lib/device/simulator-management.d.ts.map +1 -0
- package/build/lib/{simulator-management.js → device/simulator-management.js} +24 -43
- package/build/lib/device/simulator-management.js.map +1 -0
- package/build/lib/driver.d.ts +129 -1385
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +476 -600
- package/build/lib/driver.js.map +1 -1
- package/build/lib/method-map.d.ts +1 -1
- package/build/lib/method-map.d.ts.map +1 -1
- package/build/lib/method-map.js +2 -2
- package/build/lib/method-map.js.map +1 -1
- package/lib/app-utils.js +5 -1
- package/lib/commands/app-management.js +2 -2
- package/lib/commands/appearance.js +2 -2
- package/lib/commands/biometric.js +3 -3
- package/lib/commands/certificate.js +9 -3
- package/lib/commands/context.js +6 -6
- package/lib/commands/file-movement.js +11 -7
- package/lib/commands/general.js +1 -1
- package/lib/commands/gesture.js +1 -1
- package/lib/commands/keychains.js +1 -1
- package/lib/commands/localization.js +1 -1
- package/lib/commands/location.js +1 -1
- package/lib/commands/log.js +7 -7
- package/lib/commands/memory.js +1 -1
- package/lib/commands/notifications.js +1 -1
- package/lib/commands/pasteboard.js +2 -2
- package/lib/commands/pcap.js +1 -1
- package/lib/commands/performance.js +12 -1
- package/lib/commands/permissions.js +2 -2
- package/lib/commands/proxy-helper.js +0 -3
- package/lib/commands/screenshots.js +1 -1
- package/lib/commands/simctl.js +1 -1
- package/lib/commands/web.js +1 -1
- package/lib/commands/xctest-record-screen.js +2 -2
- package/lib/{desired-caps.js → desired-caps.ts} +7 -6
- package/lib/{real-device-clients → device/clients}/py-ios-device-client.ts +1 -1
- package/lib/{device-connections-factory.js → device/device-connections-factory.ts} +96 -60
- package/lib/{device-log → device/log}/helpers.ts +1 -1
- package/lib/{device-log → device/log}/ios-crash-log.ts +3 -3
- package/lib/{device-log → device/log}/ios-log.ts +1 -1
- package/lib/{device-log → device/log}/line-consuming-log.ts +1 -1
- package/lib/{device-log → device/log}/safari-console-log.ts +1 -1
- package/lib/device/real-device-management.ts +819 -0
- package/lib/{simulator-management.js → device/simulator-management.ts} +69 -62
- package/lib/{driver.js → driver.ts} +619 -713
- package/lib/{method-map.js → method-map.ts} +5 -2
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -1
- package/build/lib/device-connections-factory.d.ts +0 -13
- package/build/lib/device-connections-factory.d.ts.map +0 -1
- package/build/lib/device-connections-factory.js.map +0 -1
- package/build/lib/device-log/helpers.d.ts.map +0 -1
- package/build/lib/device-log/helpers.js.map +0 -1
- package/build/lib/device-log/ios-crash-log.d.ts.map +0 -1
- package/build/lib/device-log/ios-crash-log.js.map +0 -1
- package/build/lib/device-log/ios-device-log.d.ts.map +0 -1
- package/build/lib/device-log/ios-device-log.js.map +0 -1
- package/build/lib/device-log/ios-log.d.ts.map +0 -1
- package/build/lib/device-log/ios-log.js.map +0 -1
- package/build/lib/device-log/ios-performance-log.d.ts.map +0 -1
- package/build/lib/device-log/ios-performance-log.js.map +0 -1
- package/build/lib/device-log/ios-simulator-log.d.ts.map +0 -1
- package/build/lib/device-log/ios-simulator-log.js.map +0 -1
- package/build/lib/device-log/line-consuming-log.d.ts.map +0 -1
- package/build/lib/device-log/line-consuming-log.js.map +0 -1
- package/build/lib/device-log/safari-console-log.d.ts.map +0 -1
- package/build/lib/device-log/safari-console-log.js.map +0 -1
- package/build/lib/device-log/safari-network-log.d.ts.map +0 -1
- package/build/lib/device-log/safari-network-log.js.map +0 -1
- package/build/lib/ios-fs-helpers.d.ts +0 -75
- package/build/lib/ios-fs-helpers.d.ts.map +0 -1
- package/build/lib/ios-fs-helpers.js +0 -370
- package/build/lib/ios-fs-helpers.js.map +0 -1
- package/build/lib/real-device-clients/base-device-client.d.ts.map +0 -1
- package/build/lib/real-device-clients/base-device-client.js.map +0 -1
- package/build/lib/real-device-clients/py-ios-device-client.d.ts.map +0 -1
- package/build/lib/real-device-clients/py-ios-device-client.js.map +0 -1
- package/build/lib/real-device-management.d.ts +0 -53
- package/build/lib/real-device-management.d.ts.map +0 -1
- package/build/lib/real-device-management.js +0 -128
- package/build/lib/real-device-management.js.map +0 -1
- package/build/lib/real-device.d.ts +0 -112
- package/build/lib/real-device.d.ts.map +0 -1
- package/build/lib/real-device.js +0 -352
- package/build/lib/real-device.js.map +0 -1
- package/build/lib/simulator-management.d.ts +0 -96
- package/build/lib/simulator-management.d.ts.map +0 -1
- package/build/lib/simulator-management.js.map +0 -1
- package/build/lib/xcrun.d.ts +0 -3
- package/build/lib/xcrun.d.ts.map +0 -1
- package/build/lib/xcrun.js +0 -17
- package/build/lib/xcrun.js.map +0 -1
- package/lib/ios-fs-helpers.js +0 -355
- package/lib/real-device-management.js +0 -133
- package/lib/real-device.js +0 -347
- package/lib/xcrun.js +0 -16
- /package/build/lib/{real-device-clients → device/clients}/base-device-client.d.ts +0 -0
- /package/build/lib/{real-device-clients → device/clients}/base-device-client.js +0 -0
- /package/build/lib/{real-device-clients → device/clients}/py-ios-device-client.js +0 -0
- /package/build/lib/{device-log → device/log}/helpers.js +0 -0
- /package/build/lib/{device-log → device/log}/ios-device-log.d.ts +0 -0
- /package/build/lib/{device-log → device/log}/ios-device-log.js +0 -0
- /package/build/lib/{device-log → device/log}/ios-log.js +0 -0
- /package/build/lib/{device-log → device/log}/ios-performance-log.d.ts +0 -0
- /package/build/lib/{device-log → device/log}/ios-performance-log.js +0 -0
- /package/build/lib/{device-log → device/log}/ios-simulator-log.d.ts +0 -0
- /package/build/lib/{device-log → device/log}/ios-simulator-log.js +0 -0
- /package/build/lib/{device-log → device/log}/line-consuming-log.js +0 -0
- /package/build/lib/{device-log → device/log}/safari-console-log.js +0 -0
- /package/build/lib/{device-log → device/log}/safari-network-log.d.ts +0 -0
- /package/build/lib/{device-log → device/log}/safari-network-log.js +0 -0
- /package/lib/{real-device-clients → device/clients}/base-device-client.ts +0 -0
- /package/lib/{device-log → device/log}/ios-device-log.ts +0 -0
- /package/lib/{device-log → device/log}/ios-performance-log.ts +0 -0
- /package/lib/{device-log → device/log}/ios-simulator-log.ts +0 -0
- /package/lib/{device-log → device/log}/safari-network-log.ts +0 -0
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.RealDevice = exports.IO_TIMEOUT_MS = void 0;
|
|
40
|
+
exports.pullFile = pullFile;
|
|
41
|
+
exports.pullFolder = pullFolder;
|
|
42
|
+
exports.pushFile = pushFile;
|
|
43
|
+
exports.pushFolder = pushFolder;
|
|
44
|
+
exports.getConnectedDevices = getConnectedDevices;
|
|
45
|
+
exports.installToRealDevice = installToRealDevice;
|
|
46
|
+
exports.runRealDeviceReset = runRealDeviceReset;
|
|
47
|
+
exports.applySafariStartupArgs = applySafariStartupArgs;
|
|
48
|
+
exports.detectUdid = detectUdid;
|
|
49
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
50
|
+
const bluebird_1 = __importStar(require("bluebird"));
|
|
51
|
+
const support_1 = require("appium/support");
|
|
52
|
+
const path_1 = __importDefault(require("path"));
|
|
53
|
+
const appium_ios_device_1 = require("appium-ios-device");
|
|
54
|
+
const app_utils_1 = require("../app-utils");
|
|
55
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
56
|
+
const node_devicectl_1 = require("node-devicectl");
|
|
57
|
+
const DEFAULT_APP_INSTALLATION_TIMEOUT_MS = 8 * 60 * 1000;
|
|
58
|
+
exports.IO_TIMEOUT_MS = 4 * 60 * 1000;
|
|
59
|
+
// Mobile devices use NAND memory modules for the storage,
|
|
60
|
+
// and the parallelism there is not as performant as on regular SSDs
|
|
61
|
+
const MAX_IO_CHUNK_SIZE = 8;
|
|
62
|
+
const APPLICATION_INSTALLED_NOTIFICATION = 'com.apple.mobile.application_installed';
|
|
63
|
+
const APPLICATION_NOTIFICATION_TIMEOUT_MS = 30 * 1000;
|
|
64
|
+
const INSTALLATION_STAGING_DIR = 'PublicStaging';
|
|
65
|
+
//#region Public File System Functions
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve a file from a real device
|
|
68
|
+
*
|
|
69
|
+
* @param afcService Apple File Client service instance from
|
|
70
|
+
* 'appium-ios-device' module
|
|
71
|
+
* @param remotePath Relative path to the file on the device
|
|
72
|
+
* @returns The file content as a buffer
|
|
73
|
+
*/
|
|
74
|
+
async function pullFile(afcService, remotePath) {
|
|
75
|
+
const stream = await afcService.createReadStream(remotePath, { autoDestroy: true });
|
|
76
|
+
const pullPromise = new bluebird_1.default((resolve, reject) => {
|
|
77
|
+
stream.on('close', resolve);
|
|
78
|
+
stream.on('error', reject);
|
|
79
|
+
}).timeout(exports.IO_TIMEOUT_MS);
|
|
80
|
+
const buffers = [];
|
|
81
|
+
stream.on('data', (data) => buffers.push(data));
|
|
82
|
+
await pullPromise;
|
|
83
|
+
return Buffer.concat(buffers);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Retrieve a folder from a real device
|
|
87
|
+
*
|
|
88
|
+
* @param afcService Apple File Client service instance from
|
|
89
|
+
* 'appium-ios-device' module
|
|
90
|
+
* @param remoteRootPath Relative path to the folder on the device
|
|
91
|
+
* @returns The folder content as a zipped base64-encoded buffer
|
|
92
|
+
*/
|
|
93
|
+
async function pullFolder(afcService, remoteRootPath) {
|
|
94
|
+
const tmpFolder = await support_1.tempDir.openDir();
|
|
95
|
+
try {
|
|
96
|
+
let localTopItem = null;
|
|
97
|
+
let countFilesSuccess = 0;
|
|
98
|
+
let countFilesFail = 0;
|
|
99
|
+
let countFolders = 0;
|
|
100
|
+
const pullPromises = [];
|
|
101
|
+
await afcService.walkDir(remoteRootPath, true, async (remotePath, isDir) => {
|
|
102
|
+
const localPath = path_1.default.join(tmpFolder, remotePath);
|
|
103
|
+
const dirname = isDir ? localPath : path_1.default.dirname(localPath);
|
|
104
|
+
if (!(await folderExists(dirname))) {
|
|
105
|
+
await (0, support_1.mkdirp)(dirname);
|
|
106
|
+
}
|
|
107
|
+
if (!localTopItem || localPath.split(path_1.default.sep).length < localTopItem.split(path_1.default.sep).length) {
|
|
108
|
+
localTopItem = localPath;
|
|
109
|
+
}
|
|
110
|
+
if (isDir) {
|
|
111
|
+
++countFolders;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const readStream = await afcService.createReadStream(remotePath, { autoDestroy: true });
|
|
115
|
+
const writeStream = support_1.fs.createWriteStream(localPath, { autoClose: true });
|
|
116
|
+
pullPromises.push(new bluebird_1.default((resolve) => {
|
|
117
|
+
writeStream.on('close', () => {
|
|
118
|
+
++countFilesSuccess;
|
|
119
|
+
resolve();
|
|
120
|
+
});
|
|
121
|
+
const onStreamingError = (e) => {
|
|
122
|
+
readStream.unpipe(writeStream);
|
|
123
|
+
logger_1.default.warn(`Cannot pull '${remotePath}' to '${localPath}'. ` +
|
|
124
|
+
`The file will be skipped. Original error: ${e.message}`);
|
|
125
|
+
++countFilesFail;
|
|
126
|
+
resolve();
|
|
127
|
+
};
|
|
128
|
+
writeStream.on('error', onStreamingError);
|
|
129
|
+
readStream.on('error', onStreamingError);
|
|
130
|
+
}).timeout(exports.IO_TIMEOUT_MS));
|
|
131
|
+
readStream.pipe(writeStream);
|
|
132
|
+
if (pullPromises.length >= MAX_IO_CHUNK_SIZE) {
|
|
133
|
+
await bluebird_1.default.any(pullPromises);
|
|
134
|
+
for (let i = pullPromises.length - 1; i >= 0; i--) {
|
|
135
|
+
if (pullPromises[i].isFulfilled()) {
|
|
136
|
+
pullPromises.splice(i, 1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// Wait for the rest of files to be pulled
|
|
142
|
+
if (!lodash_1.default.isEmpty(pullPromises)) {
|
|
143
|
+
await bluebird_1.default.all(pullPromises);
|
|
144
|
+
}
|
|
145
|
+
logger_1.default.info(`Pulled ${support_1.util.pluralize('file', countFilesSuccess, true)} out of ` +
|
|
146
|
+
`${countFilesSuccess + countFilesFail} and ${support_1.util.pluralize('folder', countFolders, true)} ` +
|
|
147
|
+
`from '${remoteRootPath}'`);
|
|
148
|
+
return await support_1.zip.toInMemoryZip(localTopItem ? path_1.default.dirname(localTopItem) : tmpFolder, {
|
|
149
|
+
encodeToBase64: true,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
await support_1.fs.rimraf(tmpFolder);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Pushes a file to a real device
|
|
158
|
+
*
|
|
159
|
+
* @param afcService afcService Apple File Client service instance from
|
|
160
|
+
* 'appium-ios-device' module
|
|
161
|
+
* @param localPathOrPayload Either full path to the source file
|
|
162
|
+
* or a buffer payload to be written into the remote destination
|
|
163
|
+
* @param remotePath Relative path to the file on the device. The remote
|
|
164
|
+
* folder structure is created automatically if necessary.
|
|
165
|
+
* @param opts Push file options
|
|
166
|
+
*/
|
|
167
|
+
async function pushFile(afcService, localPathOrPayload, remotePath, opts = {}) {
|
|
168
|
+
const { timeoutMs = exports.IO_TIMEOUT_MS } = opts;
|
|
169
|
+
const timer = new support_1.timing.Timer().start();
|
|
170
|
+
await remoteMkdirp(afcService, path_1.default.dirname(remotePath));
|
|
171
|
+
const source = Buffer.isBuffer(localPathOrPayload)
|
|
172
|
+
? localPathOrPayload
|
|
173
|
+
: support_1.fs.createReadStream(localPathOrPayload, { autoClose: true });
|
|
174
|
+
const writeStream = await afcService.createWriteStream(remotePath, {
|
|
175
|
+
autoDestroy: true,
|
|
176
|
+
});
|
|
177
|
+
writeStream.on('finish', writeStream.destroy);
|
|
178
|
+
let pushError = null;
|
|
179
|
+
const filePushPromise = new bluebird_1.default((resolve, reject) => {
|
|
180
|
+
writeStream.on('close', () => {
|
|
181
|
+
if (pushError) {
|
|
182
|
+
reject(pushError);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
resolve();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
const onStreamError = (e) => {
|
|
189
|
+
if (!Buffer.isBuffer(source)) {
|
|
190
|
+
source.unpipe(writeStream);
|
|
191
|
+
}
|
|
192
|
+
logger_1.default.debug(e);
|
|
193
|
+
pushError = e;
|
|
194
|
+
};
|
|
195
|
+
writeStream.on('error', onStreamError);
|
|
196
|
+
if (!Buffer.isBuffer(source)) {
|
|
197
|
+
source.on('error', onStreamError);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
if (Buffer.isBuffer(source)) {
|
|
201
|
+
writeStream.write(source);
|
|
202
|
+
writeStream.end();
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
source.pipe(writeStream);
|
|
206
|
+
}
|
|
207
|
+
await filePushPromise.timeout(Math.max(timeoutMs, 60000));
|
|
208
|
+
const fileSize = Buffer.isBuffer(localPathOrPayload)
|
|
209
|
+
? localPathOrPayload.length
|
|
210
|
+
: (await support_1.fs.stat(localPathOrPayload)).size;
|
|
211
|
+
logger_1.default.debug(`Successfully pushed the file payload (${support_1.util.toReadableSizeString(fileSize)}) ` +
|
|
212
|
+
`to the remote location '${remotePath}' in ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Pushes a folder to a real device
|
|
216
|
+
*
|
|
217
|
+
* @param afcService Apple File Client service instance from
|
|
218
|
+
* 'appium-ios-device' module
|
|
219
|
+
* @param srcRootPath The full path to the source folder
|
|
220
|
+
* @param dstRootPath The relative path to the destination folder. The folder
|
|
221
|
+
* will be deleted if already exists.
|
|
222
|
+
* @param opts Push folder options
|
|
223
|
+
*/
|
|
224
|
+
async function pushFolder(afcService, srcRootPath, dstRootPath, opts = {}) {
|
|
225
|
+
const { timeoutMs = exports.IO_TIMEOUT_MS, enableParallelPush = false } = opts;
|
|
226
|
+
const timer = new support_1.timing.Timer().start();
|
|
227
|
+
const allItems = /** @type {import('path-scurry').Path[]} */ (
|
|
228
|
+
/** @type {unknown} */ (await support_1.fs.glob('**', {
|
|
229
|
+
cwd: srcRootPath,
|
|
230
|
+
withFileTypes: true,
|
|
231
|
+
})));
|
|
232
|
+
logger_1.default.debug(`Successfully scanned the tree structure of '${srcRootPath}'`);
|
|
233
|
+
// top-level folders go first
|
|
234
|
+
const foldersToPush = allItems
|
|
235
|
+
.filter((x) => x.isDirectory())
|
|
236
|
+
.map((x) => x.relative())
|
|
237
|
+
.sort((a, b) => a.split(path_1.default.sep).length - b.split(path_1.default.sep).length);
|
|
238
|
+
// larger files go first
|
|
239
|
+
const filesToPush = allItems
|
|
240
|
+
.filter((x) => !x.isDirectory())
|
|
241
|
+
.sort((a, b) => (b.size ?? 0) - (a.size ?? 0))
|
|
242
|
+
.map((x) => x.relative());
|
|
243
|
+
logger_1.default.debug(`Got ${support_1.util.pluralize('folder', foldersToPush.length, true)} and ` +
|
|
244
|
+
`${support_1.util.pluralize('file', filesToPush.length, true)} to push`);
|
|
245
|
+
// create the folder structure first
|
|
246
|
+
try {
|
|
247
|
+
await afcService.deleteDirectory(dstRootPath);
|
|
248
|
+
}
|
|
249
|
+
catch { }
|
|
250
|
+
await afcService.createDirectory(dstRootPath);
|
|
251
|
+
for (const relativeFolderPath of foldersToPush) {
|
|
252
|
+
// createDirectory does not accept folder names ending with a path separator
|
|
253
|
+
const absoluteFolderPath = lodash_1.default.trimEnd(path_1.default.join(dstRootPath, relativeFolderPath), path_1.default.sep);
|
|
254
|
+
if (absoluteFolderPath) {
|
|
255
|
+
await afcService.createDirectory(absoluteFolderPath);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// do not forget about the root folder
|
|
259
|
+
logger_1.default.debug(`Successfully created the remote folder structure ` +
|
|
260
|
+
`(${support_1.util.pluralize('item', foldersToPush.length + 1, true)})`);
|
|
261
|
+
const _pushFile = async (relativePath) => {
|
|
262
|
+
const absoluteSourcePath = path_1.default.join(srcRootPath, relativePath);
|
|
263
|
+
const readStream = support_1.fs.createReadStream(absoluteSourcePath, { autoClose: true });
|
|
264
|
+
const absoluteDestinationPath = path_1.default.join(dstRootPath, relativePath);
|
|
265
|
+
const writeStream = await afcService.createWriteStream(absoluteDestinationPath, {
|
|
266
|
+
autoDestroy: true,
|
|
267
|
+
});
|
|
268
|
+
writeStream.on('finish', writeStream.destroy);
|
|
269
|
+
let pushError = null;
|
|
270
|
+
const filePushPromise = new bluebird_1.default((resolve, reject) => {
|
|
271
|
+
writeStream.on('close', () => {
|
|
272
|
+
if (pushError) {
|
|
273
|
+
reject(pushError);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
resolve();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const onStreamError = (e) => {
|
|
280
|
+
readStream.unpipe(writeStream);
|
|
281
|
+
logger_1.default.debug(e);
|
|
282
|
+
pushError = e;
|
|
283
|
+
};
|
|
284
|
+
writeStream.on('error', onStreamError);
|
|
285
|
+
readStream.on('error', onStreamError);
|
|
286
|
+
});
|
|
287
|
+
readStream.pipe(writeStream);
|
|
288
|
+
await filePushPromise.timeout(Math.max(timeoutMs - timer.getDuration().asMilliSeconds, 60000));
|
|
289
|
+
};
|
|
290
|
+
if (enableParallelPush) {
|
|
291
|
+
logger_1.default.debug(`Proceeding to parallel files push (max ${MAX_IO_CHUNK_SIZE} writers)`);
|
|
292
|
+
const pushPromises = [];
|
|
293
|
+
for (const relativeFilePath of filesToPush) {
|
|
294
|
+
pushPromises.push(bluebird_1.default.resolve(_pushFile(relativeFilePath)));
|
|
295
|
+
// keep the push queue filled
|
|
296
|
+
if (pushPromises.length >= MAX_IO_CHUNK_SIZE) {
|
|
297
|
+
await bluebird_1.default.any(pushPromises);
|
|
298
|
+
const elapsedMs = timer.getDuration().asMilliSeconds;
|
|
299
|
+
if (elapsedMs > timeoutMs) {
|
|
300
|
+
throw new bluebird_1.TimeoutError(`Timed out after ${elapsedMs} ms`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
for (let i = pushPromises.length - 1; i >= 0; i--) {
|
|
304
|
+
if (pushPromises[i].isFulfilled()) {
|
|
305
|
+
pushPromises.splice(i, 1);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (!lodash_1.default.isEmpty(pushPromises)) {
|
|
310
|
+
const remainingPromises = pushPromises.filter((p) => !p.isFulfilled());
|
|
311
|
+
if (remainingPromises.length > 0) {
|
|
312
|
+
await bluebird_1.default.all(remainingPromises).timeout(Math.max(timeoutMs - timer.getDuration().asMilliSeconds, 60000));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
logger_1.default.debug(`Proceeding to serial files push`);
|
|
318
|
+
for (const relativeFilePath of filesToPush) {
|
|
319
|
+
await _pushFile(relativeFilePath);
|
|
320
|
+
const elapsedMs = timer.getDuration().asMilliSeconds;
|
|
321
|
+
if (elapsedMs > timeoutMs) {
|
|
322
|
+
throw new bluebird_1.TimeoutError(`Timed out after ${elapsedMs} ms`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
logger_1.default.debug(`Successfully pushed ${support_1.util.pluralize('folder', foldersToPush.length, true)} ` +
|
|
327
|
+
`and ${support_1.util.pluralize('file', filesToPush.length, true)} ` +
|
|
328
|
+
`within ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
|
|
329
|
+
}
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region Public Device Connection Functions
|
|
332
|
+
/**
|
|
333
|
+
* Get list of connected devices
|
|
334
|
+
*/
|
|
335
|
+
async function getConnectedDevices() {
|
|
336
|
+
if (['yes', 'true', '1'].includes(lodash_1.default.toLower(process.env.APPIUM_XCUITEST_PREFER_DEVICECTL))) {
|
|
337
|
+
return (await new node_devicectl_1.Devicectl('').listDevices())
|
|
338
|
+
.map(({ hardwareProperties }) => hardwareProperties?.udid)
|
|
339
|
+
.filter(Boolean);
|
|
340
|
+
}
|
|
341
|
+
return await appium_ios_device_1.utilities.getConnectedDevices();
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region Public Real Device Class
|
|
345
|
+
class RealDevice {
|
|
346
|
+
udid;
|
|
347
|
+
_log;
|
|
348
|
+
devicectl;
|
|
349
|
+
constructor(udid, logger) {
|
|
350
|
+
this.udid = udid;
|
|
351
|
+
this._log = logger ?? logger_1.default;
|
|
352
|
+
this.devicectl = new node_devicectl_1.Devicectl(this.udid);
|
|
353
|
+
}
|
|
354
|
+
get log() {
|
|
355
|
+
return this._log;
|
|
356
|
+
}
|
|
357
|
+
async remove(bundleId) {
|
|
358
|
+
const service = await appium_ios_device_1.services.startInstallationProxyService(this.udid);
|
|
359
|
+
try {
|
|
360
|
+
await service.uninstallApplication(bundleId);
|
|
361
|
+
}
|
|
362
|
+
finally {
|
|
363
|
+
service.close();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async removeApp(bundleId) {
|
|
367
|
+
await this.remove(bundleId);
|
|
368
|
+
}
|
|
369
|
+
async install(appPath, bundleId, opts = {}) {
|
|
370
|
+
const { timeoutMs = exports.IO_TIMEOUT_MS, } = opts;
|
|
371
|
+
const timer = new support_1.timing.Timer().start();
|
|
372
|
+
const afcService = await appium_ios_device_1.services.startAfcService(this.udid);
|
|
373
|
+
try {
|
|
374
|
+
let bundlePathOnPhone;
|
|
375
|
+
if ((await support_1.fs.stat(appPath)).isFile()) {
|
|
376
|
+
// https://github.com/doronz88/pymobiledevice3/blob/6ff5001f5776e03b610363254e82d7fbcad4ef5f/pymobiledevice3/services/installation_proxy.py#L75
|
|
377
|
+
bundlePathOnPhone = `/${path_1.default.basename(appPath)}`;
|
|
378
|
+
await pushFile(afcService, appPath, bundlePathOnPhone, {
|
|
379
|
+
timeoutMs,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
bundlePathOnPhone = `${INSTALLATION_STAGING_DIR}/${bundleId}`;
|
|
384
|
+
await pushFolder(afcService, appPath, bundlePathOnPhone, {
|
|
385
|
+
enableParallelPush: true,
|
|
386
|
+
timeoutMs,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
await this.installOrUpgradeApplication(bundlePathOnPhone, {
|
|
390
|
+
timeout: Math.max(timeoutMs - timer.getDuration().asMilliSeconds, 60000),
|
|
391
|
+
isUpgrade: await this.isAppInstalled(bundleId),
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
this.log.debug(err.stack);
|
|
396
|
+
let errMessage = `Cannot install the ${bundleId} application`;
|
|
397
|
+
if (err instanceof bluebird_1.TimeoutError) {
|
|
398
|
+
errMessage += `. Consider increasing the value of 'appPushTimeout' capability (the current value equals to ${timeoutMs}ms)`;
|
|
399
|
+
}
|
|
400
|
+
errMessage += `. Original error: ${err.message}`;
|
|
401
|
+
throw new Error(errMessage);
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
afcService.close();
|
|
405
|
+
}
|
|
406
|
+
this.log.info(`The installation of '${bundleId}' succeeded after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
|
|
407
|
+
}
|
|
408
|
+
async installOrUpgradeApplication(bundlePathOnPhone, opts) {
|
|
409
|
+
const { isUpgrade, timeout } = opts;
|
|
410
|
+
const notificationService = await appium_ios_device_1.services.startNotificationProxyService(this.udid);
|
|
411
|
+
const installationService = await appium_ios_device_1.services.startInstallationProxyService(this.udid);
|
|
412
|
+
const appInstalledNotification = new bluebird_1.default((resolve) => {
|
|
413
|
+
notificationService.observeNotification(APPLICATION_INSTALLED_NOTIFICATION, {
|
|
414
|
+
notification: resolve,
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
const clientOptions = { PackageType: 'Developer' };
|
|
418
|
+
try {
|
|
419
|
+
if (isUpgrade) {
|
|
420
|
+
this.log.debug(`An upgrade of the existing application is going to be performed. ` +
|
|
421
|
+
`Will timeout in ${timeout.toFixed(0)} ms`);
|
|
422
|
+
await installationService.upgradeApplication(bundlePathOnPhone, clientOptions, timeout);
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
this.log.debug(`A new application installation is going to be performed. ` +
|
|
426
|
+
`Will timeout in ${timeout.toFixed(0)} ms`);
|
|
427
|
+
await installationService.installApplication(bundlePathOnPhone, clientOptions, timeout);
|
|
428
|
+
}
|
|
429
|
+
try {
|
|
430
|
+
await appInstalledNotification.timeout(APPLICATION_NOTIFICATION_TIMEOUT_MS, `Could not get the application installed notification within ` +
|
|
431
|
+
`${APPLICATION_NOTIFICATION_TIMEOUT_MS}ms but we will continue`);
|
|
432
|
+
}
|
|
433
|
+
catch (e) {
|
|
434
|
+
this.log.warn(e.message);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
finally {
|
|
438
|
+
installationService.close();
|
|
439
|
+
notificationService.close();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Alias for {@linkcode install}
|
|
444
|
+
*/
|
|
445
|
+
async installApp(appPath, bundleId, opts = {}) {
|
|
446
|
+
return await this.install(appPath, bundleId, opts);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Return an application object if test app has 'bundleid'.
|
|
450
|
+
* The target bundleid can be User and System apps.
|
|
451
|
+
*
|
|
452
|
+
* @param bundleId The bundleId to ensure it is installed
|
|
453
|
+
* @returns Returns True if the app is installed on the device under test.
|
|
454
|
+
*/
|
|
455
|
+
async isAppInstalled(bundleId) {
|
|
456
|
+
return Boolean(await this.fetchAppInfo(bundleId));
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Fetches various attributes, like bundle id, version, entitlements etc. of
|
|
460
|
+
* an installed application.
|
|
461
|
+
*
|
|
462
|
+
* @param bundleId the bundle identifier of an app to check
|
|
463
|
+
* @param returnAttributes If provided then
|
|
464
|
+
* only fetches the requested attributes of the app into the resulting object.
|
|
465
|
+
* Some apps may have too many attributes, so it makes sense to limit these
|
|
466
|
+
* by default if you don't need all of them.
|
|
467
|
+
* @returns Either app info as an object or undefined if the app is not found.
|
|
468
|
+
*/
|
|
469
|
+
async fetchAppInfo(bundleId, returnAttributes = ['CFBundleIdentifier', 'CFBundleVersion']) {
|
|
470
|
+
const service = await appium_ios_device_1.services.startInstallationProxyService(this.udid);
|
|
471
|
+
try {
|
|
472
|
+
return (await service.lookupApplications({
|
|
473
|
+
bundleIds: bundleId,
|
|
474
|
+
// https://github.com/appium/appium/issues/18753
|
|
475
|
+
returnAttributes,
|
|
476
|
+
}))[bundleId];
|
|
477
|
+
}
|
|
478
|
+
finally {
|
|
479
|
+
service.close();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
async terminateApp(bundleId, platformVersion) {
|
|
483
|
+
let instrumentService;
|
|
484
|
+
let installProxyService;
|
|
485
|
+
try {
|
|
486
|
+
installProxyService = await appium_ios_device_1.services.startInstallationProxyService(this.udid);
|
|
487
|
+
const apps = await installProxyService.listApplications({
|
|
488
|
+
returnAttributes: ['CFBundleIdentifier', 'CFBundleExecutable']
|
|
489
|
+
});
|
|
490
|
+
if (!apps[bundleId]) {
|
|
491
|
+
this.log.info(`The bundle id '${bundleId}' did not exist`);
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
const executableName = apps[bundleId].CFBundleExecutable;
|
|
495
|
+
this.log.debug(`The executable name for the bundle id '${bundleId}' was '${executableName}'`);
|
|
496
|
+
// 'devicectl' has overhead (generally?) than the instrument service via appium-ios-device,
|
|
497
|
+
// so hre uses the 'devicectl' only for iOS 17+.
|
|
498
|
+
if (support_1.util.compareVersions(platformVersion, '>=', '17.0')) {
|
|
499
|
+
this.log.debug(`Calling devicectl to kill the process`);
|
|
500
|
+
const pids = (await this.devicectl.listProcesses())
|
|
501
|
+
.filter(({ executable }) => executable.endsWith(`/${executableName}`))
|
|
502
|
+
.map(({ processIdentifier }) => processIdentifier);
|
|
503
|
+
if (lodash_1.default.isEmpty(pids)) {
|
|
504
|
+
this.log.info(`The process of the bundle id '${bundleId}' was not running`);
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
await this.devicectl.sendSignalToProcess(pids[0], 2);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
instrumentService = await appium_ios_device_1.services.startInstrumentService(this.udid);
|
|
511
|
+
// The result of "runningProcesses" includes `bundle_id` key in iOS 16+ (possibly a specific 16.x+)
|
|
512
|
+
// then here may not be necessary to find a process with `CFBundleExecutable`
|
|
513
|
+
// after dropping older iOS version support.
|
|
514
|
+
const processes = await instrumentService.callChannel(appium_ios_device_1.INSTRUMENT_CHANNEL.DEVICE_INFO, 'runningProcesses');
|
|
515
|
+
const process = processes.selector.find((process) => process.name === executableName);
|
|
516
|
+
if (!process) {
|
|
517
|
+
this.log.info(`The process of the bundle id '${bundleId}' was not running`);
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
await instrumentService.callChannel(appium_ios_device_1.INSTRUMENT_CHANNEL.PROCESS_CONTROL, 'killPid:', `${process.pid}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
catch (err) {
|
|
524
|
+
this.log.warn(`Failed to kill '${bundleId}'. Original error: ${err.stderr || err.message}`);
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
finally {
|
|
528
|
+
if (installProxyService) {
|
|
529
|
+
installProxyService.close();
|
|
530
|
+
}
|
|
531
|
+
if (instrumentService) {
|
|
532
|
+
instrumentService.close();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* @param bundleName The name of CFBundleName in Info.plist
|
|
539
|
+
*
|
|
540
|
+
* @returns A list of User level apps' bundle ids which has
|
|
541
|
+
* 'CFBundleName' attribute as 'bundleName'.
|
|
542
|
+
*/
|
|
543
|
+
async getUserInstalledBundleIdsByBundleName(bundleName) {
|
|
544
|
+
const service = await appium_ios_device_1.services.startInstallationProxyService(this.udid);
|
|
545
|
+
try {
|
|
546
|
+
const applications = await service.listApplications({
|
|
547
|
+
applicationType: 'User', returnAttributes: ['CFBundleIdentifier', 'CFBundleName']
|
|
548
|
+
});
|
|
549
|
+
return lodash_1.default.reduce(applications, (acc, { CFBundleName }, key) => {
|
|
550
|
+
if (CFBundleName === bundleName) {
|
|
551
|
+
acc.push(key);
|
|
552
|
+
}
|
|
553
|
+
return acc;
|
|
554
|
+
}, []);
|
|
555
|
+
}
|
|
556
|
+
finally {
|
|
557
|
+
service.close();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async getPlatformVersion() {
|
|
561
|
+
return await appium_ios_device_1.utilities.getOSVersion(this.udid);
|
|
562
|
+
}
|
|
563
|
+
async reset(opts) {
|
|
564
|
+
const { bundleId, fullReset } = opts;
|
|
565
|
+
if (!bundleId || !fullReset || bundleId === app_utils_1.SAFARI_BUNDLE_ID) {
|
|
566
|
+
// Safari cannot be removed as system app.
|
|
567
|
+
// Safari process handling will be managed by WDA
|
|
568
|
+
// with noReset, forceAppLaunch or shouldTerminateApp capabilities.
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
this.log.debug(`Reset: fullReset requested. Will try to uninstall the app '${bundleId}'.`);
|
|
572
|
+
if (!(await this.isAppInstalled(bundleId))) {
|
|
573
|
+
this.log.debug('Reset: app not installed. No need to uninstall');
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
await this.remove(bundleId);
|
|
578
|
+
}
|
|
579
|
+
catch (err) {
|
|
580
|
+
this.log.error(`Reset: could not remove '${bundleId}' from device: ${err.message}`);
|
|
581
|
+
throw err;
|
|
582
|
+
}
|
|
583
|
+
this.log.debug(`Reset: removed '${bundleId}'`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
exports.RealDevice = RealDevice;
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region Public Device Management Functions
|
|
589
|
+
/**
|
|
590
|
+
* Install app to real device
|
|
591
|
+
*/
|
|
592
|
+
async function installToRealDevice(app, bundleId, opts = {}) {
|
|
593
|
+
const device = this.device;
|
|
594
|
+
if (!device.udid || !app || !bundleId) {
|
|
595
|
+
this.log.debug('No device id, app or bundle id, not installing to real device.');
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const { skipUninstall, timeout = DEFAULT_APP_INSTALLATION_TIMEOUT_MS, } = opts;
|
|
599
|
+
if (!skipUninstall) {
|
|
600
|
+
this.log.info(`Reset requested. Removing app with id '${bundleId}' from the device`);
|
|
601
|
+
await device.remove(bundleId);
|
|
602
|
+
}
|
|
603
|
+
this.log.debug(`Installing '${app}' on the device with UUID '${device.udid}'`);
|
|
604
|
+
try {
|
|
605
|
+
await device.install(app, bundleId, {
|
|
606
|
+
timeoutMs: timeout,
|
|
607
|
+
});
|
|
608
|
+
this.log.debug('The app has been installed successfully.');
|
|
609
|
+
}
|
|
610
|
+
catch (e) {
|
|
611
|
+
// Want to clarify the device's application installation state in this situation.
|
|
612
|
+
if (!skipUninstall || !e.message.includes('MismatchedApplicationIdentifierEntitlement')) {
|
|
613
|
+
// Other error cases that could not be recoverable by here.
|
|
614
|
+
// Exact error will be in the log.
|
|
615
|
+
// We cannot recover 'ApplicationVerificationFailed' situation since this reason is clearly the app's provisioning profile was invalid.
|
|
616
|
+
// [XCUITest] Error installing app '/path/to.app': Unexpected data: {"Error":"ApplicationVerificationFailed","ErrorDetail":-402620395,"ErrorDescription":"Failed to verify code signature of /path/to.app : 0xe8008015 (A valid provisioning profile for this executable was not found.)"}
|
|
617
|
+
throw e;
|
|
618
|
+
}
|
|
619
|
+
// If the error was by below error case, we could recover the situation
|
|
620
|
+
// by uninstalling the device's app bundle id explicitly regard less the app exists on the device or not (e.g. offload app).
|
|
621
|
+
// [XCUITest] Error installing app '/path/to.app': Unexpected data: {"Error":"MismatchedApplicationIdentifierEntitlement","ErrorDescription":"Upgrade's application-identifier entitlement string (TEAM_ID.com.kazucocoa.example) does not match installed application's application-identifier string (ANOTHER_TEAM_ID.com.kazucocoa.example); rejecting upgrade."}
|
|
622
|
+
this.log.info(`The application identified by '${bundleId}' cannot be installed because it might ` +
|
|
623
|
+
`be already cached on the device, probably with a different signature. ` +
|
|
624
|
+
`Will try to remove it and install a new copy. Original error: ${e.message}`);
|
|
625
|
+
await device.remove(bundleId);
|
|
626
|
+
await device.install(app, bundleId, {
|
|
627
|
+
timeoutMs: timeout,
|
|
628
|
+
});
|
|
629
|
+
this.log.debug('The app has been installed after one retrial.');
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Run real device reset
|
|
634
|
+
*/
|
|
635
|
+
async function runRealDeviceReset() {
|
|
636
|
+
if (!this.opts.noReset || this.opts.fullReset) {
|
|
637
|
+
this.log.debug('Reset: running ios real device reset flow');
|
|
638
|
+
if (!this.opts.noReset) {
|
|
639
|
+
await this.device.reset(this.opts);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
this.log.debug('Reset: fullReset not set. Leaving as is');
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Configures Safari startup options based on the given session capabilities.
|
|
648
|
+
*
|
|
649
|
+
* !!! This method mutates driver options.
|
|
650
|
+
*
|
|
651
|
+
* @returns true if process arguments have been modified
|
|
652
|
+
*/
|
|
653
|
+
function applySafariStartupArgs() {
|
|
654
|
+
const prefs = (0, app_utils_1.buildSafariPreferences)(this.opts);
|
|
655
|
+
if (lodash_1.default.isEmpty(prefs)) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
const args = lodash_1.default.toPairs(prefs)
|
|
659
|
+
.flatMap(([key, value]) => [lodash_1.default.startsWith(key, '-') ? key : `-${key}`, String(value)]);
|
|
660
|
+
logger_1.default.debug(`Generated Safari command line arguments: ${args.join(' ')}`);
|
|
661
|
+
const processArguments = this.opts.processArguments;
|
|
662
|
+
if (processArguments && lodash_1.default.isPlainObject(processArguments)) {
|
|
663
|
+
processArguments.args = [...(processArguments.args ?? []), ...args];
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
this.opts.processArguments = { args };
|
|
667
|
+
}
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Auto-detect device UDID
|
|
672
|
+
*/
|
|
673
|
+
async function detectUdid() {
|
|
674
|
+
this.log.debug('Auto-detecting real device udid...');
|
|
675
|
+
const udids = await getConnectedDevices();
|
|
676
|
+
if (lodash_1.default.isEmpty(udids)) {
|
|
677
|
+
throw new Error('No real devices are connected to the host');
|
|
678
|
+
}
|
|
679
|
+
const udid = udids[udids.length - 1];
|
|
680
|
+
if (udids.length > 1) {
|
|
681
|
+
this.log.info(`Multiple devices found: ${udids.join(', ')}`);
|
|
682
|
+
this.log.info(`Choosing '${udid}'. Consider settings the 'udid' capability if another device must be selected`);
|
|
683
|
+
}
|
|
684
|
+
this.log.debug(`Detected real device udid: '${udid}'`);
|
|
685
|
+
return udid;
|
|
686
|
+
}
|
|
687
|
+
//#endregion
|
|
688
|
+
//#region Private Helper Functions
|
|
689
|
+
/**
|
|
690
|
+
* Checks a presence of a local folder.
|
|
691
|
+
*
|
|
692
|
+
* @param folderPath Full path to the local folder
|
|
693
|
+
* @returns True if the folder exists and is actually a folder
|
|
694
|
+
*/
|
|
695
|
+
async function folderExists(folderPath) {
|
|
696
|
+
try {
|
|
697
|
+
return (await support_1.fs.stat(folderPath)).isDirectory();
|
|
698
|
+
}
|
|
699
|
+
catch {
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Creates remote folder path recursively. Noop if the given path
|
|
705
|
+
* already exists
|
|
706
|
+
*
|
|
707
|
+
* @param afcService Apple File Client service instance from
|
|
708
|
+
* 'appium-ios-device' module
|
|
709
|
+
* @param remoteRoot The relative path to the remote folder structure
|
|
710
|
+
* to be created
|
|
711
|
+
*/
|
|
712
|
+
async function remoteMkdirp(afcService, remoteRoot) {
|
|
713
|
+
if (remoteRoot === '.' || remoteRoot === '/') {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
try {
|
|
717
|
+
await afcService.listDirectory(remoteRoot);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
// This means that the directory is missing and we got an object not found error.
|
|
722
|
+
// Therefore, we are going to the parent
|
|
723
|
+
await remoteMkdirp(afcService, path_1.default.dirname(remoteRoot));
|
|
724
|
+
}
|
|
725
|
+
await afcService.createDirectory(remoteRoot);
|
|
726
|
+
}
|
|
727
|
+
//#endregion
|
|
728
|
+
//# sourceMappingURL=real-device-management.js.map
|