Merge pull request #1522 from jlipps/master

ensure ios flicks don't return control too soon (fix#742)
This commit is contained in:
Jonathan Lipps
2013-11-21 14:27:40 -08:00
4 changed files with 43 additions and 10 deletions

View File

@@ -34,9 +34,23 @@ exports.proxy = function(command, cb) {
// was thinking we should use a queue for commands instead of writing to a file
logger.info('Pushing command to appium work queue: ' + JSON.stringify(command));
this.push([command, cb]);
if (typeof command === "object") {
command = JSON.stringify(command);
}
};
exports.proxyWithMinTime = function(command, ms, cb) {
// was thinking we should use a queue for commands instead of writing to a file
var start = Date.now();
logger.info('Pushing command to appium work queue: ' + JSON.stringify(command));
this.push([command, function() {
var args = Array.prototype.slice.call(arguments, 0);
var waitNeeded = ms - (Date.now() - start);
if (waitNeeded > 0) {
setTimeout(function() {
cb.apply(null, args);
}, waitNeeded);
} else {
cb.apply(null, args);
}
}]);
};
exports.waitForCondition = function(waitMs, condFn, cb, intervalMs) {

View File

@@ -18,6 +18,7 @@ var uuid = require('uuid-js')
, NotYetImplementedError = errors.NotYetImplementedError;
var iOSController = {};
var FLICK_MS = 3000;
var logTypesSupported = {
'syslog' : 'Logs for iOS applications on real device and simulators'
@@ -914,18 +915,18 @@ iOSController.fakeFlick = function(xSpeed, ySpeed, swipe, cb) {
var command = "";
if (swipe) {
command = ["au.touchSwipeFromSpeed(", xSpeed, ",", ySpeed,")"].join('');
}
else {
this.proxy(command, cb);
} else {
command = ["au.touchFlickFromSpeed(", xSpeed, ",", ySpeed,")"].join('');
this.proxyWithMinTime(command, FLICK_MS, cb);
}
this.proxy(command, cb);
};
iOSController.fakeFlickElement = function(elementId, xoffset, yoffset, speed, cb) {
var command = ["au.getElement('", elementId, "').touchFlick(", xoffset, ",", yoffset, ",", speed, ")"].join('');
this.proxy(command, cb);
var command = ["au.getElement('", elementId, "').touchFlick(", xoffset, ",",
yoffset, ",", speed, ")"].join('');
this.proxyWithMinTime(command, FLICK_MS, cb);
};
iOSController.drag = function(startX, startY, endX, endY, steps, elementId, destElId, cb) {
@@ -1002,7 +1003,7 @@ iOSController.flick = function(startX, startY, endX, endY, touchCount, elId,
command = ["au.flickApp(", startX, ',', startY, ',', endX, ',', endY,
")"].join('');
}
this.proxy(command, cb);
this.proxyWithMinTime(command, FLICK_MS, cb);
};
iOSController.scrollTo = function(elementId, text, cb) {

View File

@@ -741,6 +741,7 @@ IOS.prototype.stop = function(cb) {
IOS.prototype.waitForCondition = deviceCommon.waitForCondition;
IOS.prototype.proxy = deviceCommon.proxy;
IOS.prototype.proxyWithMinTime = deviceCommon.proxyWithMinTime;
IOS.prototype.respond = deviceCommon.respond;
IOS.prototype.push = function(elem) {

View File

@@ -37,6 +37,14 @@ describeWd('flick gesture', function(h) {
});
});
});
it('should not complete instantaneously', function(done) {
var start = Date.now();
h.driver.execute("mobile: flick", [{endX: 0, endY: 0}], function(err) {
should.not.exist(err);
(Date.now() - start).should.be.above(2500);
done();
});
});
it('should work via mobile only method with percentage', function(done) {
h.driver.elementByTagName('tableCell', function(err, element) {
element.getLocation(function(err, location) {
@@ -133,6 +141,15 @@ describeWd('swipe gesture', function(h) {
});
});
});
it('should not complete instantaneously', function(done) {
var start = Date.now();
var opts = {startX: 0.5, startY: 0.9, endX: 0.5, endY: 0.7, duration: 2};
h.driver.execute("mobile: swipe", [opts], function(err) {
should.not.exist(err);
(Date.now() - start).should.be.above(1999);
done();
});
});
});
describeWd("flick element", function(h) {