Skip to content

Commit

Permalink
casper: Add waitForSelectorText.
Browse files Browse the repository at this point in the history
  • Loading branch information
umairwaheed authored and timabbott committed Jun 7, 2017
1 parent 9ebb503 commit e4f6f53
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions frontend_tests/casper_lib/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var util = require("util");
var REALMS_HAVE_SUBDOMAINS = casper.cli.get('subdomains');
var common = (function () {

Expand Down Expand Up @@ -74,6 +75,21 @@ exports.initialize_casper = function () {
});
});

// This function should always be enclosed within a then() otherwise
// it might not exist on casper object.
casper.waitForSelectorText = function (selector, text, then, onTimeout, timeout) {
this.waitForSelector(selector, function _then() {
this.waitFor(function _check() {
var content = this.fetchText(selector);
if (util.isRegExp(text)) {
return text.test(content);
}
return content.indexOf(text) !== -1;
}, then, onTimeout, timeout);
}, onTimeout, timeout);
return this;
};

casper.evaluate(function () {
window.localStorage.clear();
});
Expand Down

0 comments on commit e4f6f53

Please sign in to comment.