From e55b32fb45beaa256b3e3c3829e72a265d9fa84b Mon Sep 17 00:00:00 2001 From: sebv Date: Mon, 7 Jul 2014 15:50:29 +0800 Subject: [PATCH] resetting commandTimeout at each step of the implicitTimeout cycle --- lib/appium.js | 2 + lib/devices/android/android-controller.js | 2 +- lib/devices/android/android.js | 3 ++ lib/devices/common.js | 14 +++++++ lib/devices/ios/ios-controller.js | 4 +- lib/devices/ios/ios.js | 2 + .../testapp/timeout/implicit-wait-specs.js | 38 ++++++++++++------- 7 files changed, 48 insertions(+), 17 deletions(-) diff --git a/lib/appium.js b/lib/appium.js index 90569da49..12c4edff8 100644 --- a/lib/appium.js +++ b/lib/appium.js @@ -266,6 +266,8 @@ Appium.prototype.configure = function (args, desiredCaps, cb) { } this.device = this.getNewDevice(deviceType); this.device.configure(args, desiredCaps, cb); + // TODO: better collaboration between the Appium and Device objects + this.device.onResetTimeout = function () { this.resetTimeout(); }.bind(this); }; Appium.prototype.invoke = function (cb) { diff --git a/lib/devices/android/android-controller.js b/lib/devices/android/android-controller.js index 4cbf5140a..3a9324b40 100644 --- a/lib/devices/android/android-controller.js +++ b/lib/devices/android/android-controller.js @@ -68,7 +68,7 @@ androidController.findUIElementOrElements = function (strategy, selector, many, }.bind(this)); } }.bind(this); - this.waitForCondition(this.implicitWaitMs, doFind, cb); + this.implicitWaitForCondition(doFind, cb); }; androidController.handleFindCb = function (err, res, many, findCb) { diff --git a/lib/devices/android/android.js b/lib/devices/android/android.js index a4c683d2d..e2a364bcb 100644 --- a/lib/devices/android/android.js +++ b/lib/devices/android/android.js @@ -507,7 +507,10 @@ Android.prototype.waitForActivityToStop = function (cb) { this.adb.waitForNotActivity(this.args.appWaitPackage, this.args.appWaitActivity, cb); }; + +Android.prototype.resetTimeout = deviceCommon.resetTimeout; Android.prototype.waitForCondition = deviceCommon.waitForCondition; +Android.prototype.implicitWaitForCondition = deviceCommon.implicitWaitForCondition; _.extend(Android.prototype, androidController); _.extend(Android.prototype, androidContextController); diff --git a/lib/devices/common.js b/lib/devices/common.js index 7560d8c85..66c016da0 100644 --- a/lib/devices/common.js +++ b/lib/devices/common.js @@ -52,6 +52,10 @@ exports.proxyWithMinTime = function (command, ms, cb) { }]); }; +exports.resetTimeout = function () { + if (this.onResetTimeout) this.onResetTimeout(); +}; + exports.waitForCondition = function (waitMs, condFn, cb, intervalMs) { if (typeof intervalMs === "undefined") { intervalMs = 500; @@ -73,6 +77,16 @@ exports.waitForCondition = function (waitMs, condFn, cb, intervalMs) { spin(); }; +exports.implicitWaitForCondition = function (condFn, cb) { + var _condFn = condFn; + condFn = function () { + var args = Array.prototype.slice.call(arguments, 0); + this.resetTimeout(); + _condFn.apply(this, args); + }.bind(this); + this.waitForCondition(this.implicitWaitMs, condFn, cb); +}; + exports.doRequest = function (url, method, body, contentType, cb) { if (typeof cb === "undefined" && typeof contentType === "function") { cb = contentType; diff --git a/lib/devices/ios/ios-controller.js b/lib/devices/ios/ios-controller.js index 860645e19..c42d81955 100644 --- a/lib/devices/ios/ios-controller.js +++ b/lib/devices/ios/ios-controller.js @@ -121,7 +121,7 @@ iOSController.findUIElementOrElements = function (strategy, selector, ctx, many, }.bind(this); if (_.contains(this.supportedStrategies, strategy)) { - this.waitForCondition(this.implicitWaitMs, doFind, cb); + this.implicitWaitForCondition(doFind, cb); } else { cb(null, { status: status.codes.UnknownError.code @@ -295,7 +295,7 @@ iOSController.findWebElementOrElements = function (strategy, selector, ctx, many this.handleFindCb(err, res, many, findCb); }.bind(this)); }.bind(this); - this.waitForCondition(this.implicitWaitMs, doFind, cb); + this.implicitWaitForCondition(doFind, cb); }; iOSController.findElementOrElements = function (strategy, selector, ctx, many, cb) { diff --git a/lib/devices/ios/ios.js b/lib/devices/ios/ios.js index deb460798..1c65bea03 100644 --- a/lib/devices/ios/ios.js +++ b/lib/devices/ios/ios.js @@ -1281,7 +1281,9 @@ IOS.prototype.shutdown = function (code, traceDir, cb) { }; +IOS.prototype.resetTimeout = deviceCommon.resetTimeout; IOS.prototype.waitForCondition = deviceCommon.waitForCondition; +IOS.prototype.implicitWaitForCondition = deviceCommon.implicitWaitForCondition; IOS.prototype.proxy = deviceCommon.proxy; IOS.prototype.proxyWithMinTime = deviceCommon.proxyWithMinTime; IOS.prototype.respond = deviceCommon.respond; diff --git a/test/functional/ios/testapp/timeout/implicit-wait-specs.js b/test/functional/ios/testapp/timeout/implicit-wait-specs.js index 710d460ec..98db6a17d 100644 --- a/test/functional/ios/testapp/timeout/implicit-wait-specs.js +++ b/test/functional/ios/testapp/timeout/implicit-wait-specs.js @@ -11,29 +11,39 @@ describe('testapp - timeout', function () { var driver; setup(this, desired).then(function (d) { driver = d; }); - var impWaitSecs = 4; - var impWaitCheck = function () { - var before = new Date().getTime() / 1000; - return driver - .elementsByClassName('UIANotGonnaBeThere').then(function (missing) { - var after = new Date().getTime() / 1000; - (after - before).should.be.below(impWaitSecs + 2); - (after - before).should.be.above(impWaitSecs); - missing.should.have.length(0); - }); + var impWaitCheck = function (impWaitMs) { + return function () { + var before = new Date().getTime(); + return driver + .elementsByClassName('UIANotGonnaBeThere').then(function (missing) { + var after = new Date().getTime(); + (after - before).should.be.below(impWaitMs + 2000); + (after - before).should.be.above(impWaitMs); + missing.should.have.length(0); + }); + }; }; it('should set the implicit wait for finding elements', function (done) { driver - .setImplicitWaitTimeout(impWaitSecs * 1000) - .then(impWaitCheck) + .setImplicitWaitTimeout(4000) + .then(impWaitCheck(4000)) + .nodeify(done); + }); + + it('should work with small command timeout', function (done) { + driver + .setCommandTimeout(5000) + .setImplicitWaitTimeout(10000) + .then(impWaitCheck(10000)) .nodeify(done); }); it('should work even with a reset in the middle', function (done) { driver - .setImplicitWaitTimeout(impWaitSecs * 1000) - .then(impWaitCheck) + .setCommandTimeout(60000) + .setImplicitWaitTimeout(4000) + .then(impWaitCheck(4000)) .resetApp() .sleep(3000) // cooldown .then(impWaitCheck)