Merge pull request #2066 from bootstraponline/android_push

Android mobile push & pull
This commit is contained in:
Jonathan Lipps
2014-03-14 13:44:05 -07:00
4 changed files with 102 additions and 0 deletions

View File

@@ -448,6 +448,55 @@ androidController.localScreenshot = function (file, cb) {
});
};
androidController.pullFile = function (remotePath, cb) {
var localFile = temp.path({prefix: 'appium', suffix: '.tmp'});
var b64data = "";
async.series([
function (cb) {
this.adb.pull(remotePath, localFile, cb);
}.bind(this),
function (cb) {
fs.readFile(localFile, function (err, data) {
if (err) return cb(err);
b64data = new Buffer(data).toString('base64');
cb();
});
}.bind(this),
],
function (err) {
if (fs.existsSync(localFile)) fs.unlinkSync(localFile);
if (err) return cb(err);
cb(null, {
status: status.codes.Success.code
, value: b64data
});
});
};
androidController.pushFile = function (base64Data, remotePath, cb) {
var localFile = temp.path({prefix: 'appium', suffix: '.tmp'});
async.series([
function (cb) {
var content = new Buffer(base64Data, 'base64');
var fd = fs.openSync(localFile, 'w');
fs.writeSync(fd, content, 0, content.length, 0);
fs.closeSync(fd);
// adb push creates folders and overwrites existing files.
this.adb.push(localFile, remotePath, cb);
}.bind(this),
],
function (err) {
if (fs.existsSync(localFile)) fs.unlinkSync(localFile);
if (err) return cb(err);
cb(null, {
status: status.codes.Success.code
});
});
};
androidController.getScreenshot = function (cb) {
var localfile = temp.path({prefix: 'appium', suffix: '.png'});
var b64data = "";

View File

@@ -263,6 +263,14 @@ iOSController.nonSyntheticWebClick = function (elementId, cb) {
}.bind(this));
};
iOSController.pushFile = function (base64Data, remotePath, cb) {
cb(new NotYetImplementedError(), null);
};
iOSController.pullFile = function (remotePath, cb) {
cb(new NotYetImplementedError(), null);
};
iOSController.touchLongClick = function (elementId, cb) {
cb(new NotYetImplementedError(), null);
};

View File

@@ -975,6 +975,23 @@ exports.localScreenshot = function (req, res) {
}
};
exports.pushFile = function (req, res) {
var data = req.body.data; // base64 data
var path = req.body.path; // remote path
if (checkMissingParams(res, {data: data, path: path})) {
req.device.pushFile(data, path, getResponseHandler(req, res));
}
};
exports.pullFile = function (req, res) {
var path = req.body.path; // remote path
if (checkMissingParams(res, {path: path})) {
req.device.pullFile(path, getResponseHandler(req, res));
}
};
exports.endCoverage = function (req, res) {
var intent = req.body.intent;
var path = req.body.path;
@@ -1045,6 +1062,8 @@ var mobileCmdMap = {
, 'toggleWiFi': exports.toggleWiFi
, 'toggleLocationServices': exports.toggleLocationServices
, 'endCoverage': exports.endCoverage
, 'pushFile': exports.pushFile
, 'pullFile': exports.pullFile
};
exports.produceError = function (req, res) {

View File

@@ -0,0 +1,26 @@
"use strict";
var setup = require("../../common/setup-base")
, desired = require("./desired")
, fs = require('fs');
describe("apidemos - push & pull file -", function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
it('should push and pull a file', function (done) {
var stringData = "random string data " + Math.random();
var base64Data = new Buffer(stringData).toString('base64');
var remotePath = '/data/local/tmp/remote.txt';
driver.execute("mobile: pushFile", [{data: base64Data, path: remotePath}])
.then(function () {
return driver.execute("mobile: pullFile", [{path: remotePath}]);
})
.then(function (remoteData64) {
var remoteData = new Buffer(remoteData64, 'base64').toString();
remoteData.should.equal(stringData);
})
.nodeify(done);
});
});