mirror of
https://github.com/appium/appium.git
synced 2026-02-09 11:18:51 -06:00
resetting commandTimeout at each step of the implicitTimeout cycle
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user