Skip to content

Commit

Permalink
Implementing WaitFor* and WaitForNot* commands in Selenium IDE Webdri…
Browse files Browse the repository at this point in the history
…ver playback. Fixes issue SeleniumHQ#5913
  • Loading branch information
samitbadle committed Aug 12, 2013
1 parent 257d96a commit a27be1e
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions ide/main/src/content/remote-selenium-commandhandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ objectExtend(CommandHandlerFactory.prototype, {

_predicateForSingleArgAccessor: function(accessBlock) {
// Given an accessor function getBlah(target),
// return a "predicate" equivalient to isBlah(target, value) that
// return a "predicate" equivalent to isBlah(target, value) that
// is true when the value returned by the accessor matches the specified value.
return function(target, value) {
return accessBlock(target).pipe(function(accessorResult) {
Expand Down Expand Up @@ -227,14 +227,28 @@ objectExtend(CommandHandlerFactory.prototype, {
_waitForActionForPredicate: function(predicateBlock) {
// Convert an isBlahBlah(target, value) function into a waitForBlahBlah(target, value) function.
return function(target, value) {
var deferred = null;
var terminationCondition = function () {
try {
return predicateBlock(target, value).isTrue;
if (!deferred) {
deferred = predicateBlock(target, value);
}
if (!deferred.isPending()) {
var pResult = deferred.value()[0];
if (deferred.isRejected()) {
throw pResult;
}
deferred = null;
return pResult.isTrue;
}
return false;

} catch (e) {
// Treat exceptions as meaning the condition is not yet met.
// Useful, for example, for waitForValue when the element has
// not even been created yet.
// TODO: possibly should rethrow some types of exception.
deferred = null;
return false;
}
};
Expand Down Expand Up @@ -320,10 +334,14 @@ ActionHandler.prototype.execute = function(seleniumApi, command) {
var terminationCondition = function() {
//TODO Samit: need to handle wait for page to load?
if (handlerCondition) {
if (handlerCondition.isRejected()) {
throw handlerCondition.value()[0];
if (Deferred.isPromise(handlerCondition)) {
if (handlerCondition.isRejected()) {
throw handlerCondition.value()[0];
}
return !handlerCondition.isPending();
} else {
return handlerCondition();
}
return !handlerCondition.isPending();
}
return true;
};
Expand Down

0 comments on commit a27be1e

Please sign in to comment.