diff --git a/lib/devices/ios/ios-controller.js b/lib/devices/ios/ios-controller.js index 5fa77b9d3..d7e2bb5fa 100644 --- a/lib/devices/ios/ios-controller.js +++ b/lib/devices/ios/ios-controller.js @@ -411,7 +411,47 @@ iOSController.nativeWebTap = function (elementId, cb) { }; iOSController.pushFile = function (base64Data, remotePath, cb) { - cb(new NotYetImplementedError(), null); + if (this.realDevice) { + logger.debug("Unsupported: cannot write files to physical device"); + return cb(new NotYetImplementedError(), null); + } + + logger.debug("Pushing " + remotePath + " to iOS simulator"); + + var writeFile = function (err, fullPath) { + if (err) return cb(err); + logger.debug("Attempting to write " + fullPath + "..."); + + async.series([ + function (cb) { + try { + if (fs.existsSync(fullPath)) { + logger.debug(fullPath + " already exists, deleting..."); + fs.unlinkSync(fullPath); + } + + mkdirp.sync(path.dirname(fullPath)); + + var content = new Buffer(base64Data, 'base64'); + var fd = fs.openSync(fullPath, 'w'); + fs.writeSync(fd, content, 0, content.length, 0); + fs.closeSync(fd); + logger.debug("Wrote " + content.length + "bytes to " + fullPath); + cb(null); + } catch (e) { + cb(e); + } + }.bind(this), + ], function (err) { + logger.debug("Returning response"); + if (err) return cb(err); + cb(null, { + status: status.codes.Success.code + }); + }); + }; + + this._getFullPath(remotePath, writeFile); }; /* diff --git a/lib/server/main.js b/lib/server/main.js index 87604ee6a..254444470 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -100,7 +100,7 @@ var main = function (args, readyCb, doneCb) { rest.use(allowCrossDomain); rest.use(parserWrap); rest.use(bodyParser.urlencoded({extended: true})); - rest.use(bodyParser.json()); + rest.use(bodyParser.json({limit: '50mb'})); rest.use(morgan({format: function (tokens, req, res) { // morgan output is redirected straight to winston var data = ''; diff --git a/test/functional/ios/file-movement-specs.js b/test/functional/ios/file-movement-specs.js index fc900c211..f083c411e 100644 --- a/test/functional/ios/file-movement-specs.js +++ b/test/functional/ios/file-movement-specs.js @@ -10,7 +10,7 @@ var setup = require("../common/setup-base") , exec = require('child_process').exec , Unzip = require('unzip'); -describe('file movements - pullFile', function () { +describe('file movements - pullFile and pushFile', function () { var driver; var desired = { app: getAppPath('testapp') @@ -32,6 +32,21 @@ describe('file movements - pullFile', function () { .should.eventually.be.rejectedWith(/13/) .nodeify(done); }); + it('should be able to push and pull a file', function (done) { + var stringData = "random string data " + Math.random(); + var base64Data = new Buffer(stringData).toString('base64'); + var remotePath = 'Library/AppiumTest/remote.txt'; + + driver + .pushFile(remotePath, base64Data) + .pullFile(remotePath) + .then(function (remoteData64) { + var remoteData = new Buffer(remoteData64, 'base64').toString(); + remoteData.should.equal(stringData); + }) + .nodeify(done); + }); + describe('for a .app @skip-ci', function () { // TODO: skipping ci because of local files use, to review. var fileContent = "IAmTheVeryModelOfAModernMajorTestingTool";