Skip to content

Commit 430005e

Browse files
Mykola Mokhnachimurchie
authored andcommitted
Add a possibility to push media files to Simulator (#516)
* Add a possibility to push media files to Simulator * Tune the minimum node-simctl version
1 parent 56d3d58 commit 430005e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

lib/commands/actions.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { fs, tempDir } from 'appium-support';
2+
import path from 'path';
3+
import { addMedia } from 'node-simctl';
4+
5+
let commands = {};
6+
7+
commands.pushFile = async function (remotePath, base64Data) {
8+
if (!this.isSimulator()) {
9+
throw new Error('Media upload is only supported on Simulator');
10+
}
11+
const dstFolder = await tempDir.tempDir();
12+
// It is important to keep the original file name,
13+
// so simctl knows where to put the file
14+
const dstPath = path.resolve(dstFolder, path.basename(remotePath));
15+
try {
16+
await fs.writeFile(dstPath, new Buffer(base64Data, 'base64').toString('binary'), 'binary');
17+
await addMedia(this.opts.udid, dstPath);
18+
} finally {
19+
await fs.rimraf(dstFolder);
20+
}
21+
};
22+
23+
export default commands;

lib/commands/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import actionsCommands from './actions';
12
import contextCommands from './context';
23
import executeExtensions from './execute';
34
import gestureExtensions from './gesture';
@@ -18,7 +19,7 @@ import pasteboardExtensions from './pasteboard';
1819

1920
let commands = {};
2021

21-
Object.assign(commands, contextCommands, executeExtensions,
22+
Object.assign(commands, actionsCommands, contextCommands, executeExtensions,
2223
gestureExtensions, findExtensions, proxyHelperExtensions, sourceExtensions,
2324
generalExtensions, logExtensions, webExtensions, timeoutExtensions,
2425
navigationExtensions, elementExtensions, fileMovementExtensions,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"babel-runtime": "=5.8.24",
3838
"bluebird": "^3.1.1",
3939
"lodash": "^4.0.0",
40-
"node-simctl": "^3.9.0",
40+
"node-simctl": "^3.10.0",
4141
"request": "^2.79.0",
4242
"request-promise": "^4.1.1",
4343
"source-map-support": "^0.4.0",

0 commit comments

Comments
 (0)