@@ -2,6 +2,7 @@ import _ from 'lodash';
2
2
import { fs , util , zip , tempDir } from 'appium/support' ;
3
3
import path from 'path' ;
4
4
import { errors } from 'appium/driver' ;
5
+ import { requireArgs } from '../utils' ;
5
6
6
7
7
8
const CONTAINER_PATH_MARKER = '@' ;
@@ -115,9 +116,31 @@ commands.pullFile = async function pullFile (remotePath) {
115
116
} ;
116
117
117
118
/**
118
- * Pushed the given data to a file on the remote device
119
+ * @typedef {Object } PullFileOptions
120
+ * @property {string } remotePath The full path to the remote file
121
+ * or a specially formatted path, which points to an item inside an app bundle,
122
+ * for example `@my.app.id/my/path`. It is mandatory for the app bundle to have
123
+ * debugging enabled in order to use the latter remotePath format.
124
+ */
125
+
126
+ /**
127
+ * Pulls a remote file from the device.
128
+ *
129
+ * @param {PullFileOptions } opts
130
+ * @returns {string } The same as `pullFile`
131
+ */
132
+ commands . mobilePullFile = async function mobilePullFile ( opts = { } ) {
133
+ const { remotePath } = requireArgs ( 'remotePath' , opts ) ;
134
+ return await this . pullFile ( remotePath ) ;
135
+ } ;
136
+
137
+ /**
138
+ * Pushes the given data to a file on the remote device
119
139
* It is required, that a package has debugging flag enabled
120
140
* in order to access its files.
141
+ * After a file is pushed it gets automatically scanned for possible
142
+ * media occurrences. If the scan succeeds then the file is added to the
143
+ * media library.
121
144
*
122
145
* @param {string } remotePath The full path to the remote file or
123
146
* a file inside a package bundle
@@ -181,6 +204,25 @@ commands.pushFile = async function pushFile (remotePath, base64Data) {
181
204
}
182
205
} ;
183
206
207
+ /**
208
+ * @typedef {Object } PushFileOptions
209
+ * @property {string } remotePath The full path to the remote file
210
+ * or a specially formatted path, which points to an item inside an app bundle,
211
+ * for example `@my.app.id/my/path`. It is mandatory for the app bundle to have
212
+ * debugging enabled in order to use the latter remotePath format.
213
+ * @property {string } payload Base64-encoded content of the file to be pushed.
214
+ */
215
+
216
+ /**
217
+ * Pushes the given data to a file on the remote device.
218
+ *
219
+ * @param {PushFileOptions } opts
220
+ */
221
+ commands . mobilePushFile = async function mobilePushFile ( opts = { } ) {
222
+ const { remotePath, payload } = requireArgs ( [ 'remotePath' , 'payload' ] , opts ) ;
223
+ return await this . pushFile ( remotePath , payload ) ;
224
+ } ;
225
+
184
226
/**
185
227
* Pulls the whole folder from the remote device
186
228
*
@@ -190,11 +232,31 @@ commands.pushFile = async function pushFile (remotePath, base64Data) {
190
232
* @throws {Error } If there was a failure while getting the folder content
191
233
*/
192
234
commands . pullFolder = async function pullFolder ( remotePath ) {
193
- let localFolder = await tempDir . path ( { prefix : 'appium' } ) ;
194
- await this . adb . pull ( remotePath , localFolder ) ;
195
- return ( await zip . toInMemoryZip ( localFolder , {
196
- encodeToBase64 : true ,
197
- } ) ) . toString ( ) ;
235
+ const tmpRoot = await tempDir . openDir ( ) ;
236
+ try {
237
+ await this . adb . pull ( remotePath , tmpRoot ) ;
238
+ return ( await zip . toInMemoryZip ( tmpRoot , {
239
+ encodeToBase64 : true ,
240
+ } ) ) . toString ( ) ;
241
+ } finally {
242
+ await fs . rimraf ( tmpRoot ) ;
243
+ }
244
+ } ;
245
+
246
+ /**
247
+ * @typedef {Object } PullFolderOptions
248
+ * @property {string } remotePath The full path to the remote folder.
249
+ */
250
+
251
+ /**
252
+ * Pulls the whole folder from the device under test.
253
+ *
254
+ * @param {PullFolderOptions } opts
255
+ * @returns {string } The same as `pullFolder`
256
+ */
257
+ commands . mobilePullFolder = async function mobilePullFolder ( opts = { } ) {
258
+ const { remotePath } = requireArgs ( 'remotePath' , opts ) ;
259
+ return await this . pullFolder ( remotePath ) ;
198
260
} ;
199
261
200
262
/**
0 commit comments