appium-xcuitest-driver 10.13.1 → 10.13.2
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/commands/certificate.d.ts +14 -19
- package/build/lib/commands/certificate.d.ts.map +1 -1
- package/build/lib/commands/certificate.js +24 -31
- package/build/lib/commands/certificate.js.map +1 -1
- package/build/lib/commands/element.d.ts +83 -67
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +111 -134
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/file-movement.d.ts +31 -42
- package/build/lib/commands/file-movement.d.ts.map +1 -1
- package/build/lib/commands/file-movement.js +146 -205
- package/build/lib/commands/file-movement.js.map +1 -1
- package/build/lib/commands/find.d.ts +20 -12
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +27 -65
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/navigation.d.ts.map +1 -1
- package/build/lib/commands/navigation.js +12 -14
- package/build/lib/commands/navigation.js.map +1 -1
- package/lib/commands/{certificate.js → certificate.ts} +55 -50
- package/lib/commands/element.ts +419 -0
- package/lib/commands/{file-movement.js → file-movement.ts} +212 -235
- package/lib/commands/find.ts +277 -0
- package/lib/commands/navigation.js +20 -14
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/lib/commands/element.js +0 -423
- package/lib/commands/find.js +0 -205
|
@@ -5,9 +5,12 @@ import {services} from 'appium-ios-device';
|
|
|
5
5
|
import {
|
|
6
6
|
pullFile as realDevicePullFile,
|
|
7
7
|
pullFolder as realDevicePullFolder,
|
|
8
|
-
pushFile as realDevicePushFile
|
|
8
|
+
pushFile as realDevicePushFile,
|
|
9
9
|
} from '../device/real-device-management';
|
|
10
10
|
import {errors} from 'appium/driver';
|
|
11
|
+
import type {Simulator} from 'appium-ios-simulator';
|
|
12
|
+
import type {XCUITestDriver} from '../driver';
|
|
13
|
+
import type {ContainerObject, ContainerRootSupplier} from './types';
|
|
11
14
|
|
|
12
15
|
const CONTAINER_PATH_MARKER = '@';
|
|
13
16
|
// https://regex101.com/r/PLdB0G/2
|
|
@@ -17,16 +20,16 @@ const CONTAINER_DOCUMENTS_PATH = 'Documents';
|
|
|
17
20
|
const OBJECT_NOT_FOUND_ERROR_MESSAGE = 'OBJECT_NOT_FOUND';
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
|
-
* Parses the actual path and the bundle identifier from the given path string
|
|
23
|
+
* Parses the actual path and the bundle identifier from the given path string.
|
|
21
24
|
*
|
|
22
|
-
* @
|
|
23
|
-
* @param
|
|
24
|
-
* match `CONTAINER_PATH_PATTERN` regexp, otherwise an error is going
|
|
25
|
-
* to be thrown. A valid string example: `@bundle.identifier:container_type/relative_path_in_container`
|
|
26
|
-
* @param {import('./types').ContainerRootSupplier|string} [containerRootSupplier] - Container root path supplier function or string value
|
|
27
|
-
* @returns {Promise<import('./types').ContainerObject>}
|
|
25
|
+
* @param remotePath - Path string matching `CONTAINER_PATH_PATTERN`, e.g. `@bundle.id:container/relative/path`
|
|
26
|
+
* @param containerRootSupplier - Container root path supplier or explicit root
|
|
28
27
|
*/
|
|
29
|
-
export async function parseContainerPath(
|
|
28
|
+
export async function parseContainerPath(
|
|
29
|
+
this: XCUITestDriver,
|
|
30
|
+
remotePath: string,
|
|
31
|
+
containerRootSupplier?: ContainerRootSupplier | string,
|
|
32
|
+
): Promise<ContainerObject> {
|
|
30
33
|
const match = CONTAINER_PATH_PATTERN.exec(remotePath);
|
|
31
34
|
if (!match) {
|
|
32
35
|
throw new Error(
|
|
@@ -35,8 +38,9 @@ export async function parseContainerPath(remotePath, containerRootSupplier) {
|
|
|
35
38
|
`relative path with a single slash. '${remotePath}' is given instead`,
|
|
36
39
|
);
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
let
|
|
41
|
+
const [, bundleIdMatch, relativePath] = match;
|
|
42
|
+
let bundleId = bundleIdMatch;
|
|
43
|
+
let containerType: string | null = null;
|
|
40
44
|
const typeSeparatorPos = bundleId.indexOf(CONTAINER_TYPE_SEPARATOR);
|
|
41
45
|
// We only consider container type exists if its length is greater than zero
|
|
42
46
|
// not counting the colon
|
|
@@ -58,12 +62,147 @@ export async function parseContainerPath(remotePath, containerRootSupplier) {
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
/**
|
|
65
|
+
* Pushes the given data to a file on the remote device.
|
|
66
|
+
*
|
|
67
|
+
* @param remotePath The full path to the remote file or
|
|
68
|
+
* a file inside a package bundle. Check the documentation on
|
|
69
|
+
* `pushFileToRealDevice` and `pushFileToSimulator` for more information
|
|
70
|
+
* on acceptable values.
|
|
71
|
+
* @param base64Data Base64 encoded data to be written to the
|
|
72
|
+
* remote file. The remote file will be silently overridden if it already exists.
|
|
73
|
+
* @throws {Error} If there was an error while pushing the data
|
|
74
|
+
*/
|
|
75
|
+
export async function pushFile(
|
|
76
|
+
this: XCUITestDriver,
|
|
77
|
+
remotePath: string,
|
|
78
|
+
base64Data: string | number[] | Buffer,
|
|
79
|
+
): Promise<void> {
|
|
80
|
+
if (remotePath.endsWith('/')) {
|
|
81
|
+
throw new errors.InvalidArgumentError(
|
|
82
|
+
`It is expected that remote path points to a file and not to a folder. ` +
|
|
83
|
+
`'${remotePath}' is given instead`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
let b64StringData: string;
|
|
87
|
+
if (_.isArray(base64Data)) {
|
|
88
|
+
// some clients (ahem) java, send a byte array encoding utf8 characters
|
|
89
|
+
// instead of a string, which would be infinitely better!
|
|
90
|
+
b64StringData = Buffer.from(base64Data).toString('utf8');
|
|
91
|
+
} else if (Buffer.isBuffer(base64Data)) {
|
|
92
|
+
b64StringData = base64Data.toString('utf8');
|
|
93
|
+
} else {
|
|
94
|
+
b64StringData = base64Data as string;
|
|
95
|
+
}
|
|
96
|
+
return this.isSimulator()
|
|
97
|
+
? await pushFileToSimulator.bind(this)(remotePath, b64StringData)
|
|
98
|
+
: await pushFileToRealDevice.bind(this)(remotePath, b64StringData);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Pushes the given data to a file on the remote device.
|
|
103
|
+
*
|
|
104
|
+
* @param remotePath - The full path to the remote file
|
|
105
|
+
* or a specially formatted path, which points to an item inside an app bundle.
|
|
106
|
+
* @param payload - Base64-encoded content of the file to be pushed.
|
|
107
|
+
*/
|
|
108
|
+
export async function mobilePushFile(
|
|
109
|
+
this: XCUITestDriver,
|
|
110
|
+
remotePath: string,
|
|
111
|
+
payload: string,
|
|
112
|
+
): Promise<void> {
|
|
113
|
+
return await this.pushFile(remotePath, payload);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Pulls a remote file from the device.
|
|
118
|
+
*
|
|
119
|
+
* @param remotePath The full path to the remote file
|
|
120
|
+
* or a specially formatted path, which points to an item inside app bundle.
|
|
121
|
+
* See the documentation for `pullFromRealDevice` and `pullFromSimulator`
|
|
122
|
+
* to get more information on acceptable values.
|
|
123
|
+
* @returns Base64 encoded content of the pulled file
|
|
124
|
+
* @throws {Error} If the pull operation failed
|
|
125
|
+
*/
|
|
126
|
+
export async function pullFile(this: XCUITestDriver, remotePath: string): Promise<string> {
|
|
127
|
+
if (remotePath.endsWith('/')) {
|
|
128
|
+
throw new errors.InvalidArgumentError(
|
|
129
|
+
`It is expected that remote path points to a file and not to a folder. ` +
|
|
130
|
+
`'${remotePath}' is given instead`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return this.isSimulator()
|
|
134
|
+
? await pullFromSimulator.bind(this)(remotePath, true)
|
|
135
|
+
: await pullFromRealDevice.bind(this)(remotePath, true);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Pulls a remote file from the device.
|
|
61
140
|
*
|
|
62
|
-
* @param
|
|
63
|
-
*
|
|
64
|
-
* @returns
|
|
141
|
+
* @param remotePath - The full path to the remote file
|
|
142
|
+
* or a specially formatted path, which points to an item inside app bundle. See the documentation for `pullFromRealDevice` and `pullFromSimulator` to get more information on acceptable values.
|
|
143
|
+
* @returns The same as in `pullFile`
|
|
65
144
|
*/
|
|
66
|
-
function
|
|
145
|
+
export async function mobilePullFile(this: XCUITestDriver, remotePath: string): Promise<string> {
|
|
146
|
+
return await this.pullFile(remotePath);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Delete a remote folder from the device.
|
|
151
|
+
*
|
|
152
|
+
* @param remotePath - The full path to the remote folder or a specially formatted path, which points to an item inside app bundle. See the documentation for `pullFromRealDevice` and `pullFromSimulator` to get more information on acceptable values.
|
|
153
|
+
* @returns Nothing
|
|
154
|
+
*/
|
|
155
|
+
export async function mobileDeleteFolder(this: XCUITestDriver, remotePath: string): Promise<void> {
|
|
156
|
+
if (!remotePath.endsWith('/')) {
|
|
157
|
+
remotePath = `${remotePath}/`;
|
|
158
|
+
}
|
|
159
|
+
await deleteFileOrFolder.bind(this)(remotePath);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Delete a remote file from the device.
|
|
164
|
+
*
|
|
165
|
+
* @param remotePath - The full path to the remote file or a specially formatted path, which points to an item inside app bundle. See the documentation for `pullFromRealDevice` and `pullFromSimulator` to get more information on acceptable values.
|
|
166
|
+
* @returns Nothing
|
|
167
|
+
*/
|
|
168
|
+
export async function mobileDeleteFile(this: XCUITestDriver, remotePath: string): Promise<void> {
|
|
169
|
+
if (remotePath.endsWith('/')) {
|
|
170
|
+
throw new errors.InvalidArgumentError(
|
|
171
|
+
`It is expected that remote path points to a file and not to a folder. ` +
|
|
172
|
+
`'${remotePath}' is given instead`,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
await deleteFileOrFolder.bind(this)(remotePath);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Pulls the whole folder from the remote device
|
|
180
|
+
*
|
|
181
|
+
* @param remotePath The full path to a folder on the
|
|
182
|
+
* remote device or a folder inside an application bundle
|
|
183
|
+
* @returns Zipped and base64-encoded content of the folder
|
|
184
|
+
* @throws {Error} If there was a failure while getting the folder content
|
|
185
|
+
*/
|
|
186
|
+
export async function pullFolder(this: XCUITestDriver, remotePath: string): Promise<string> {
|
|
187
|
+
if (!remotePath.endsWith('/')) {
|
|
188
|
+
remotePath = `${remotePath}/`;
|
|
189
|
+
}
|
|
190
|
+
return this.isSimulator()
|
|
191
|
+
? await pullFromSimulator.bind(this)(remotePath, false)
|
|
192
|
+
: await pullFromRealDevice.bind(this)(remotePath, false);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Pulls the whole folder from the device under test.
|
|
197
|
+
*
|
|
198
|
+
* @param remotePath - The full path to the remote folder
|
|
199
|
+
* @returns The same as `pullFolder`
|
|
200
|
+
*/
|
|
201
|
+
export async function mobilePullFolder(this: XCUITestDriver, remotePath: string): Promise<string> {
|
|
202
|
+
return await this.pullFolder(remotePath);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function verifyIsSubPath(originalPath: string, root: string): void {
|
|
67
206
|
const normalizedRoot = path.normalize(root);
|
|
68
207
|
const normalizedPath = path.normalize(path.dirname(originalPath));
|
|
69
208
|
// If originalPath is root, `/`, originalPath should equal to normalizedRoot
|
|
@@ -72,15 +211,12 @@ function verifyIsSubPath(originalPath, root) {
|
|
|
72
211
|
}
|
|
73
212
|
}
|
|
74
213
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*/
|
|
82
|
-
async function createAfcClient(bundleId, containerType) {
|
|
83
|
-
const udid = this.device.udid;
|
|
214
|
+
async function createAfcClient(
|
|
215
|
+
this: XCUITestDriver,
|
|
216
|
+
bundleId?: string | null,
|
|
217
|
+
containerType?: string | null,
|
|
218
|
+
): Promise<any> {
|
|
219
|
+
const udid = this.device.udid as string;
|
|
84
220
|
|
|
85
221
|
if (!bundleId) {
|
|
86
222
|
return await services.startAfcService(udid);
|
|
@@ -100,22 +236,14 @@ async function createAfcClient(bundleId, containerType) {
|
|
|
100
236
|
: await service.vendContainer(bundleId);
|
|
101
237
|
}
|
|
102
238
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @param {string} [containerType]
|
|
106
|
-
* @returns {boolean}
|
|
107
|
-
*/
|
|
108
|
-
function isDocumentsContainer(containerType) {
|
|
109
|
-
return _.toLower(containerType) === _.toLower(CONTAINER_DOCUMENTS_PATH);
|
|
239
|
+
function isDocumentsContainer(containerType?: string | null): boolean {
|
|
240
|
+
return _.toLower(containerType ?? '') === _.toLower(CONTAINER_DOCUMENTS_PATH);
|
|
110
241
|
}
|
|
111
242
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* @returns {Promise<{service: any, relativePath: string}>}
|
|
117
|
-
*/
|
|
118
|
-
async function createService(remotePath) {
|
|
243
|
+
async function createService(
|
|
244
|
+
this: XCUITestDriver,
|
|
245
|
+
remotePath: string,
|
|
246
|
+
): Promise<{service: any; relativePath: string}> {
|
|
119
247
|
if (CONTAINER_PATH_PATTERN.test(remotePath)) {
|
|
120
248
|
const {bundleId, pathInContainer, containerType} = await parseContainerPath.bind(this)(remotePath);
|
|
121
249
|
const service = await createAfcClient.bind(this)(bundleId, containerType);
|
|
@@ -132,22 +260,18 @@ async function createService(remotePath) {
|
|
|
132
260
|
/**
|
|
133
261
|
* Save the given base64 data chunk as a binary file on the Simulator under test.
|
|
134
262
|
*
|
|
135
|
-
* @
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* '@com.myapp.bla:data/RelativePathInContainer/111.png'. The '@' character at the
|
|
140
|
-
* beginning of the argument is mandatory in such case. The colon at the end of bundle identifier
|
|
141
|
-
* is optional and is used to distinguish the container type.
|
|
142
|
-
* Possible values there are 'app', 'data', 'groups', '<A specific App Group container>'.
|
|
143
|
-
* The default value is 'app'.
|
|
144
|
-
* The relative folder path is ignored if the file is going to be uploaded
|
|
145
|
-
* to the default media folder and only the file name is considered important.
|
|
146
|
-
* @param {string} base64Data - Base-64 encoded content of the file to be uploaded.
|
|
263
|
+
* @param remotePath - Remote path on the simulator. Supports bundle-id-prefixed format
|
|
264
|
+
* (e.g. `@com.myapp.bla:data/path/in/container/file.png`) to target
|
|
265
|
+
* application containers; otherwise uploads to the default media folder.
|
|
266
|
+
* @param base64Data - Base-64 encoded content of the file to be uploaded.
|
|
147
267
|
*/
|
|
148
|
-
async function pushFileToSimulator(
|
|
268
|
+
async function pushFileToSimulator(
|
|
269
|
+
this: XCUITestDriver,
|
|
270
|
+
remotePath: string,
|
|
271
|
+
base64Data: string,
|
|
272
|
+
): Promise<void> {
|
|
149
273
|
const buffer = Buffer.from(base64Data, 'base64');
|
|
150
|
-
const device =
|
|
274
|
+
const device = this.device as Simulator;
|
|
151
275
|
if (CONTAINER_PATH_PATTERN.test(remotePath)) {
|
|
152
276
|
const {bundleId, pathInContainer: dstPath} = await parseContainerPath.bind(this)(
|
|
153
277
|
remotePath,
|
|
@@ -176,24 +300,18 @@ async function pushFileToSimulator(remotePath, base64Data) {
|
|
|
176
300
|
}
|
|
177
301
|
|
|
178
302
|
/**
|
|
179
|
-
* Save the given base64 data chunk as a binary file on
|
|
303
|
+
* Save the given base64 data chunk as a binary file on a real device.
|
|
180
304
|
*
|
|
181
|
-
* @
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* `@<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>`
|
|
186
|
-
* format to pull a file or a folder from an application container of the given type.
|
|
187
|
-
* The only supported container type is 'documents'. If the container type is not set
|
|
188
|
-
* explicitly for a bundle id, then the default application container is going to be mounted
|
|
189
|
-
* (aka --container ifuse argument)
|
|
190
|
-
* e.g. If `@com.myapp.bla:documents/111.png` is provided,
|
|
191
|
-
* `On My iPhone/<app name>` in Files app will be mounted in the host machine.
|
|
192
|
-
* Base64 encoded `111.png` will be pushed into `On My iPhone/<app name>/111.png`
|
|
193
|
-
* as base64 decoded data.
|
|
194
|
-
* @param {string} base64Data - Base-64 encoded content of the file to be uploaded.
|
|
305
|
+
* @param remotePath - Remote path on the device. Supports the same bundle-id-prefixed
|
|
306
|
+
* format as simulator uploads (e.g. `@com.myapp.bla:documents/file.png`)
|
|
307
|
+
* to target application containers; otherwise defaults to media folder.
|
|
308
|
+
* @param base64Data - Base-64 encoded content of the file to be uploaded.
|
|
195
309
|
*/
|
|
196
|
-
async function pushFileToRealDevice(
|
|
310
|
+
async function pushFileToRealDevice(
|
|
311
|
+
this: XCUITestDriver,
|
|
312
|
+
remotePath: string,
|
|
313
|
+
base64Data: string,
|
|
314
|
+
): Promise<void> {
|
|
197
315
|
const {service, relativePath} = await createService.bind(this)(remotePath);
|
|
198
316
|
try {
|
|
199
317
|
await realDevicePushFile(service, Buffer.from(base64Data, 'base64'), relativePath);
|
|
@@ -205,13 +323,7 @@ async function pushFileToRealDevice(remotePath, base64Data) {
|
|
|
205
323
|
}
|
|
206
324
|
}
|
|
207
325
|
|
|
208
|
-
|
|
209
|
-
*
|
|
210
|
-
* @this {XCUITestDriver}
|
|
211
|
-
* @param {string} remotePath
|
|
212
|
-
* @returns {Promise<void>}
|
|
213
|
-
*/
|
|
214
|
-
async function deleteFileOrFolder(remotePath) {
|
|
326
|
+
async function deleteFileOrFolder(this: XCUITestDriver, remotePath: string): Promise<void> {
|
|
215
327
|
return this.isSimulator()
|
|
216
328
|
? await deleteFromSimulator.bind(this)(remotePath)
|
|
217
329
|
: await deleteFromRealDevice.bind(this)(remotePath);
|
|
@@ -221,19 +333,22 @@ async function deleteFileOrFolder(remotePath) {
|
|
|
221
333
|
* Get the content of given file or folder from iOS Simulator and return it as base-64 encoded string.
|
|
222
334
|
* Folder content is recursively packed into a zip archive.
|
|
223
335
|
*
|
|
224
|
-
* @
|
|
225
|
-
* @param {string} remotePath - The path to a file or a folder, which exists in the corresponding application
|
|
336
|
+
* @param remotePath - The path to a file or a folder, which exists in the corresponding application
|
|
226
337
|
* container on Simulator. Use
|
|
227
338
|
* `@<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>`
|
|
228
339
|
* format to pull a file or a folder from an application container of the given type.
|
|
229
340
|
* Possible container types are `app`, `data`, `groups`, `<A specific App Group container>`.
|
|
230
341
|
* The default type is `app`.
|
|
231
|
-
* @param
|
|
232
|
-
* @returns
|
|
342
|
+
* @param isFile - Whether the destination item is a file or a folder
|
|
343
|
+
* @returns Base-64 encoded content of the file.
|
|
233
344
|
*/
|
|
234
|
-
async function pullFromSimulator(
|
|
345
|
+
async function pullFromSimulator(
|
|
346
|
+
this: XCUITestDriver,
|
|
347
|
+
remotePath: string,
|
|
348
|
+
isFile: boolean,
|
|
349
|
+
): Promise<string> {
|
|
235
350
|
let pathOnServer;
|
|
236
|
-
const device =
|
|
351
|
+
const device = this.device as Simulator;
|
|
237
352
|
if (CONTAINER_PATH_PATTERN.test(remotePath)) {
|
|
238
353
|
const {bundleId, pathInContainer: dstPath} = await parseContainerPath.bind(this)(
|
|
239
354
|
remotePath,
|
|
@@ -266,8 +381,7 @@ async function pullFromSimulator(remotePath, isFile) {
|
|
|
266
381
|
* Get the content of given file or folder from the real device under test and return it as base-64 encoded string.
|
|
267
382
|
* Folder content is recursively packed into a zip archive.
|
|
268
383
|
*
|
|
269
|
-
* @
|
|
270
|
-
* @param {string} remotePath - The path to an existing remote file on the device. This variable can be prefixed with
|
|
384
|
+
* @param remotePath - The path to an existing remote file on the device. This variable can be prefixed with
|
|
271
385
|
* bundle id, so then the file will be downloaded from the corresponding
|
|
272
386
|
* application container instead of the default media folder. Use
|
|
273
387
|
* `@<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>`
|
|
@@ -280,10 +394,14 @@ async function pullFromSimulator(remotePath, isFile) {
|
|
|
280
394
|
* `On My iPhone/<app name>/111.png` will be pulled into the mounted host machine
|
|
281
395
|
* and Appium returns the data as base64-encoded string to client.
|
|
282
396
|
* `@com.myapp.bla:documents/` means `On My iPhone/<app name>`.
|
|
283
|
-
* @param
|
|
284
|
-
* @returns
|
|
397
|
+
* @param isFile - Whether the destination item is a file or a folder
|
|
398
|
+
* @returns Base-64 encoded content of the remote file
|
|
285
399
|
*/
|
|
286
|
-
async function pullFromRealDevice(
|
|
400
|
+
async function pullFromRealDevice(
|
|
401
|
+
this: XCUITestDriver,
|
|
402
|
+
remotePath: string,
|
|
403
|
+
isFile: boolean,
|
|
404
|
+
): Promise<string> {
|
|
287
405
|
const {service, relativePath} = await createService.bind(this)(remotePath);
|
|
288
406
|
try {
|
|
289
407
|
const fileInfo = await service.getFileInfo(relativePath);
|
|
@@ -305,18 +423,17 @@ async function pullFromRealDevice(remotePath, isFile) {
|
|
|
305
423
|
/**
|
|
306
424
|
* Remove the file or folder from the device
|
|
307
425
|
*
|
|
308
|
-
* @
|
|
309
|
-
* @param {string} remotePath - The path to a file or a folder, which exists in the corresponding application
|
|
426
|
+
* @param remotePath - The path to a file or a folder, which exists in the corresponding application
|
|
310
427
|
* container on Simulator. Use
|
|
311
428
|
* `@<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>`
|
|
312
429
|
* format to pull a file or a folder from an application container of the given type.
|
|
313
430
|
* Possible container types are 'app', 'data', 'groups', '<A specific App Group container>'.
|
|
314
431
|
* The default type is 'app'.
|
|
315
|
-
* @returns
|
|
432
|
+
* @returns Nothing
|
|
316
433
|
*/
|
|
317
|
-
async function deleteFromSimulator(remotePath) {
|
|
318
|
-
let pathOnServer;
|
|
319
|
-
const device =
|
|
434
|
+
async function deleteFromSimulator(this: XCUITestDriver, remotePath: string): Promise<void> {
|
|
435
|
+
let pathOnServer: string;
|
|
436
|
+
const device = this.device as Simulator;
|
|
320
437
|
if (CONTAINER_PATH_PATTERN.test(remotePath)) {
|
|
321
438
|
const {bundleId, pathInContainer: dstPath} = await parseContainerPath.bind(this)(
|
|
322
439
|
remotePath,
|
|
@@ -343,8 +460,7 @@ async function deleteFromSimulator(remotePath) {
|
|
|
343
460
|
/**
|
|
344
461
|
* Remove the file or folder from the device
|
|
345
462
|
*
|
|
346
|
-
* @
|
|
347
|
-
* @param {string} remotePath - The path to an existing remote file on the device. This variable can be prefixed with
|
|
463
|
+
* @param remotePath - The path to an existing remote file on the device. This variable can be prefixed with
|
|
348
464
|
* bundle id, so then the file will be downloaded from the corresponding
|
|
349
465
|
* application container instead of the default media folder. Use
|
|
350
466
|
* `@<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container>`
|
|
@@ -357,9 +473,9 @@ async function deleteFromSimulator(remotePath) {
|
|
|
357
473
|
* `On My iPhone/<app name>/111.png` will be pulled into the mounted host machine
|
|
358
474
|
* and Appium returns the data as base64-encoded string to client.
|
|
359
475
|
* `@com.myapp.bla:documents/` means `On My iPhone/<app name>`.
|
|
360
|
-
* @returns
|
|
476
|
+
* @returns Nothing
|
|
361
477
|
*/
|
|
362
|
-
async function deleteFromRealDevice(remotePath) {
|
|
478
|
+
async function deleteFromRealDevice(this: XCUITestDriver, remotePath: string): Promise<void> {
|
|
363
479
|
const {service, relativePath} = await createService.bind(this)(remotePath);
|
|
364
480
|
try {
|
|
365
481
|
await service.deleteDirectory(relativePath);
|
|
@@ -373,142 +489,3 @@ async function deleteFromRealDevice(remotePath) {
|
|
|
373
489
|
}
|
|
374
490
|
}
|
|
375
491
|
|
|
376
|
-
/**
|
|
377
|
-
* Pushes the given data to a file on the remote device
|
|
378
|
-
*
|
|
379
|
-
* @param {string} remotePath The full path to the remote file or
|
|
380
|
-
* a file inside a package bundle. Check the documentation on
|
|
381
|
-
* `pushFileToRealDevice` and `pushFileToSimulator` for more information
|
|
382
|
-
* on acceptable values.
|
|
383
|
-
* @param {string} base64Data Base64 encoded data to be written to the
|
|
384
|
-
* remote file. The remote file will be silently overridden if it already exists.
|
|
385
|
-
* @throws {Error} If there was an error while pushing the data
|
|
386
|
-
* @this {XCUITestDriver}
|
|
387
|
-
*/
|
|
388
|
-
export async function pushFile(remotePath, base64Data) {
|
|
389
|
-
if (remotePath.endsWith('/')) {
|
|
390
|
-
throw new errors.InvalidArgumentError(
|
|
391
|
-
`It is expected that remote path points to a file and not to a folder. ` +
|
|
392
|
-
`'${remotePath}' is given instead`,
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
if (_.isArray(base64Data)) {
|
|
396
|
-
// some clients (ahem) java, send a byte array encoding utf8 characters
|
|
397
|
-
// instead of a string, which would be infinitely better!
|
|
398
|
-
base64Data = Buffer.from(base64Data).toString('utf8');
|
|
399
|
-
}
|
|
400
|
-
return this.isSimulator()
|
|
401
|
-
? await pushFileToSimulator.bind(this)(remotePath, base64Data)
|
|
402
|
-
: await pushFileToRealDevice.bind(this)(remotePath, base64Data);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Pushes the given data to a file on the remote device.
|
|
407
|
-
*
|
|
408
|
-
* @param {string} remotePath - The full path to the remote file
|
|
409
|
-
* or a specially formatted path, which points to an item inside an app bundle.
|
|
410
|
-
* @param {string} payload - Base64-encoded content of the file to be pushed.
|
|
411
|
-
* @this {XCUITestDriver}
|
|
412
|
-
*/
|
|
413
|
-
export async function mobilePushFile(remotePath, payload) {
|
|
414
|
-
return await this.pushFile(remotePath, payload);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Pulls a remote file from the device.
|
|
419
|
-
*
|
|
420
|
-
* @param {string} remotePath The full path to the remote file
|
|
421
|
-
* or a specially formatted path, which points to an item inside app bundle.
|
|
422
|
-
* See the documentation for `pullFromRealDevice` and `pullFromSimulator`
|
|
423
|
-
* to get more information on acceptable values.
|
|
424
|
-
* @returns {Promise<string>} Base64 encoded content of the pulled file
|
|
425
|
-
* @throws {Error} If the pull operation failed
|
|
426
|
-
* @this {XCUITestDriver}
|
|
427
|
-
*/
|
|
428
|
-
export async function pullFile(remotePath) {
|
|
429
|
-
if (remotePath.endsWith('/')) {
|
|
430
|
-
throw new errors.InvalidArgumentError(
|
|
431
|
-
`It is expected that remote path points to a file and not to a folder. ` +
|
|
432
|
-
`'${remotePath}' is given instead`,
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
return this.isSimulator()
|
|
436
|
-
? await pullFromSimulator.bind(this)(remotePath, true)
|
|
437
|
-
: await pullFromRealDevice.bind(this)(remotePath, true);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Pulls a remote file from the device.
|
|
442
|
-
*
|
|
443
|
-
* @param {string} remotePath - The full path to the remote file
|
|
444
|
-
* or a specially formatted path, which points to an item inside app bundle. See the documentation for `pullFromRealDevice` and `pullFromSimulator` to get more information on acceptable values.
|
|
445
|
-
* @returns {Promise<string>} The same as in `pullFile`
|
|
446
|
-
* @this {XCUITestDriver}
|
|
447
|
-
*/
|
|
448
|
-
export async function mobilePullFile(remotePath) {
|
|
449
|
-
return await this.pullFile(remotePath);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Delete a remote folder from the device.
|
|
454
|
-
*
|
|
455
|
-
* @param {string} remotePath - The full path to the remote folder or a specially formatted path, which points to an item inside app bundle. See the documentation for `pullFromRealDevice` and `pullFromSimulator` to get more information on acceptable values.
|
|
456
|
-
* @this {XCUITestDriver}
|
|
457
|
-
* @returns {Promise<void>}
|
|
458
|
-
*/
|
|
459
|
-
export async function mobileDeleteFolder(remotePath) {
|
|
460
|
-
if (!remotePath.endsWith('/')) {
|
|
461
|
-
remotePath = `${remotePath}/`;
|
|
462
|
-
}
|
|
463
|
-
await deleteFileOrFolder.bind(this)(remotePath);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Delete a remote file from the device.
|
|
468
|
-
*
|
|
469
|
-
* @param {string} remotePath - The full path to the remote file or a specially formatted path, which points to an item inside app bundle. See the documentation for `pullFromRealDevice` and `pullFromSimulator` to get more information on acceptable values.
|
|
470
|
-
* @this {XCUITestDriver}
|
|
471
|
-
* @returns {Promise<void>}
|
|
472
|
-
*/
|
|
473
|
-
export async function mobileDeleteFile(remotePath) {
|
|
474
|
-
if (remotePath.endsWith('/')) {
|
|
475
|
-
throw new errors.InvalidArgumentError(
|
|
476
|
-
`It is expected that remote path points to a file and not to a folder. ` +
|
|
477
|
-
`'${remotePath}' is given instead`,
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
await deleteFileOrFolder.bind(this)(remotePath);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* Pulls the whole folder from the remote device
|
|
485
|
-
*
|
|
486
|
-
* @param {string} remotePath The full path to a folder on the
|
|
487
|
-
* remote device or a folder inside an application bundle
|
|
488
|
-
* @returns {Promise<string>} Zipped and base64-encoded content of the folder
|
|
489
|
-
* @throws {Error} If there was a failure while getting the folder content
|
|
490
|
-
* @this {XCUITestDriver}
|
|
491
|
-
*/
|
|
492
|
-
export async function pullFolder(remotePath) {
|
|
493
|
-
if (!remotePath.endsWith('/')) {
|
|
494
|
-
remotePath = `${remotePath}/`;
|
|
495
|
-
}
|
|
496
|
-
return this.isSimulator()
|
|
497
|
-
? await pullFromSimulator.bind(this)(remotePath, false)
|
|
498
|
-
: await pullFromRealDevice.bind(this)(remotePath, false);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Pulls the whole folder from the device under test.
|
|
503
|
-
*
|
|
504
|
-
* @param {string} remotePath - The full path to the remote folder
|
|
505
|
-
* @returns {Promise<string>} The same as `pullFolder`
|
|
506
|
-
* @this {XCUITestDriver}
|
|
507
|
-
*/
|
|
508
|
-
export async function mobilePullFolder(remotePath) {
|
|
509
|
-
return await this.pullFolder(remotePath);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* @typedef {import('../driver').XCUITestDriver} XCUITestDriver
|
|
514
|
-
*/
|