From 0d4eae8cd313f833c48dedff825ab7d33fb7dcb7 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Mon, 15 Apr 2013 12:26:57 -0700 Subject: [PATCH] make sure implicit wait works after ios reset (fix #437) --- app/appium.js | 2 ++ test/functional/testapp/timeouts.js | 43 +++++++++++++++++------------ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/appium.js b/app/appium.js index b7c02637f..6e5d940a7 100644 --- a/app/appium.js +++ b/app/appium.js @@ -443,11 +443,13 @@ Appium.prototype.reset = function(cb) { logger.info("Resetting app mid-session"); if (this.isIos() || !this.fastReset) { var me = this + , oldImpWait = this.device.implicitWaitMs , oldId = this.sessionId; this.stop(function() { logger.info("Restarting app"); me.start(me.desiredCapabilities, function() { + me.device.implicitWaitMs = oldImpWait; me.sessionId = oldId; cb(null, {status: status.codes.Success.code, value: null}); }); diff --git a/test/functional/testapp/timeouts.js b/test/functional/testapp/timeouts.js index 8dd4ff90b..e1028db1c 100644 --- a/test/functional/testapp/timeouts.js +++ b/test/functional/testapp/timeouts.js @@ -24,29 +24,38 @@ describeWd('command timeout', function(h) { }); describeWd('check implicit wait', function(h) { + var impWaitSecs = 4; + var impWaitCheck = function(cb) { + var before = new Date().getTime() / 1000; + h.driver.elementsByTagName('notgonnabethere', function(err, missing) { + var after = new Date().getTime() / 1000; + should.ok(after - before < (impWaitSecs + 2)); + should.ok(after - before > impWaitSecs); + missing.length.should.equal(0); + cb(); + }); + }; + it('should set the implicit wait for finding elements', function(done) { - h.driver.setImplicitWaitTimeout(10 * 1000, function(err) { + h.driver.setImplicitWaitTimeout(impWaitSecs * 1000, function(err) { should.not.exist(err); - var before = new Date().getTime() / 1000; - h.driver.elementsByTagName('notgonnabethere', function(err, missing) { - var after = new Date().getTime() / 1000; - should.ok(after - before < 12); - should.ok(after - before > 10); - missing.length.should.equal(0); - done(); - }); + impWaitCheck(done); }); }); it('should set the implicit wait for finding element', function(done) { - h.driver.setImplicitWaitTimeout(10 * 1000, function(err) { + h.driver.setImplicitWaitTimeout(impWaitSecs * 1000, function(err) { should.not.exist(err); - var before = new Date().getTime() / 1000; - h.driver.elementByTagName('notgonnabethere', function(err) { - var after = new Date().getTime() / 1000; - should.ok(after - before < 12); - should.ok(after - before > 10); - should.exist(err); - done(); + impWaitCheck(done); + }); + }); + it('should work even with a reset in the middle', function(done) { + h.driver.setImplicitWaitTimeout(impWaitSecs * 1000, function(err) { + should.not.exist(err); + impWaitCheck(function() { + h.driver.execute("mobile: reset", function(err) { + should.not.exist(err); + impWaitCheck(done); + }); }); }); });