mirror of
https://github.com/appium/appium.git
synced 2026-05-12 22:08:40 -05:00
Merge pull request #3220 from erlendfh/ios-pushFile
Implemented pushFile for iOS controller
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -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 = '';
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user