Bug 1256439 - Run implicit wait callback once before start polling. r?automatedtester
By using a timer the first invocation of the callback is happening after the specified interval.
That means by a default of 100ms we loose that time on every call of implicit wait, and it will
slow-down the test execution drastically. To prevent this lets manually invoke the callback
before starting the timer.
MozReview-Commit-ID: Ayy1GPEaY92
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -667,17 +667,17 @@ ElementManager.prototype = {
*/
function implicitlyWaitFor(func, timeout, interval = 100) {
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
return new Promise((resolve, reject) => {
let startTime = new Date().getTime();
let endTime = startTime + timeout;
- let observer = function() {
+ let onTimer = function() {
let res;
try {
res = func();
} catch (e) {
reject(e);
}
// empty arrays evaluate to true in JS,
@@ -687,17 +687,21 @@ function implicitlyWaitFor(func, timeout
// allowing |func| to be evaluated at least once
let col = element.isElementCollection(res);
if (((col && res.length > 0 ) || (!col && !!res)) ||
(startTime == endTime || new Date().getTime() >= endTime)) {
resolve(res);
}
};
- timer.init(observer, interval, Ci.nsITimer.TYPE_REPEATING_SLACK);
+ // Run a check immediately so we do not cause a delay in execution
+ // due to the set timer interval.
+ onTimer();
+
+ timer.init(onTimer, interval, Ci.nsITimer.TYPE_REPEATING_SLACK);
// cancel timer and return result for yielding
}).then(res => {
timer.cancel();
return res;
});
}