From 4a322ba347dbbd3b0fc405a94f1d30b02dfec12e Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Thu, 21 Nov 2013 14:18:31 -0800 Subject: [PATCH] ensure ios flicks don't return control too soon (fix#742) --- lib/devices/common.js | 20 +++++++++++++++++--- lib/devices/ios/ios-controller.js | 15 ++++++++------- lib/devices/ios/ios.js | 1 + test/functional/uicatalog/gestures.js | 17 +++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/lib/devices/common.js b/lib/devices/common.js index c56c85e44..5927fad86 100644 --- a/lib/devices/common.js +++ b/lib/devices/common.js @@ -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) { diff --git a/lib/devices/ios/ios-controller.js b/lib/devices/ios/ios-controller.js index 889a46176..f21c4d86c 100644 --- a/lib/devices/ios/ios-controller.js +++ b/lib/devices/ios/ios-controller.js @@ -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) { diff --git a/lib/devices/ios/ios.js b/lib/devices/ios/ios.js index 24425c528..c9d117209 100644 --- a/lib/devices/ios/ios.js +++ b/lib/devices/ios/ios.js @@ -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) { diff --git a/test/functional/uicatalog/gestures.js b/test/functional/uicatalog/gestures.js index dbba00942..162b2a9bb 100644 --- a/test/functional/uicatalog/gestures.js +++ b/test/functional/uicatalog/gestures.js @@ -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) {