Adding retry for iOS screenshot

This commit is contained in:
Moiz Virani
2014-08-04 14:51:07 -07:00
parent e65d0e0167
commit 3eb3914707
+48 -45
View File
@@ -1186,53 +1186,56 @@ iOSController.getScreenshot = function (cb) {
}
var shotPath = [screenshotFolder, 'screenshot', guid, ".png"].join("");
async.waterfall([
function (cb) { this.getOrientation(function () { cb(); }); }.bind(this),
function (cb) { this.proxy(command, cb); }.bind(this),
function (response, cb) {
var data = null;
var count = 0;
async.until(
function () { return data; },
function (cb) {
setTimeout(function () {
fs.readFile(shotPath, function (err, _data) {
if (err && ++count > 20) {
return cb(new Error("Timed out waiting for screenshot file. " + err.toString()));
}
if (!err) {
data = _data;
}
cb();
// Retrying the whole screenshot process for three times.
async.retry(3,
function (cb) {
async.waterfall([
function (cb) { this.getOrientation(function () { cb(); }); }.bind(this),
function (cb) { this.proxy(command, cb); }.bind(this),
function (response, cb) {
var data = null;
var count = 0;
async.until(
function () { return data; },
function (cb) {
setTimeout(function () {
fs.readFile(shotPath, function (err, _data) {
if (err && ++count > 20) {
return cb(new Error("Timed out waiting for screenshot file. " + err.toString()));
}
if (!err) {
data = _data;
}
cb();
});
}, 300);
},
function (err) {
cb(err, response, data);
}
);
}.bind(this),
function (response, data, cb) {
// rotate if necessary
if (this.curOrientation === "LANDSCAPE") {
// need to rotate 90 deg CC
logger.debug("Rotating landscape screenshot");
rotateImage(shotPath, -90, function (err) {
if (err) return cb(new Error("Could not rotate screenshot appropriately"), null);
fs.readFile(shotPath, function read(err, _data) {
if (err) return cb(new Error("Could not retrieve screenshot file following rotate. " + err.toString()));
cb(null, response, _data);
});
});
}, 300);
},
function (err) {
cb(err, response, data);
} else cb(null, response, data);
}.bind(this),
function (response, data, cb) {
var b64data = new Buffer(data).toString('base64');
response.value = b64data;
cb(null, response);
}
);
}.bind(this),
function (response, data, cb) {
// rotate if necessary
if (this.curOrientation === "LANDSCAPE") {
// need to rotate 90 deg CC
logger.debug("Rotating landscape screenshot");
rotateImage(shotPath, -90, function (err) {
if (err) return cb(new Error("Could not rotate screenshot appropriately"), null);
fs.readFile(shotPath, function read(err, _data) {
if (err) return cb(new Error("Could not retrieve screenshot file following rotate. " + err.toString()));
cb(null, response, _data);
});
});
} else cb(null, response, data);
}.bind(this),
function (response, data, cb) {
var b64data = new Buffer(data).toString('base64');
response.value = b64data;
cb(null, response);
}
], cb);
], cb);
}.bind(this), cb);
};
iOSController.fakeFlick = function (xSpeed, ySpeed, swipe, cb) {