Commit 6541ac75 6541ac75914e642e930a9cf0860d66fca3939914 by Nicolas Perriault

sync with 1.0

2 parents 27440007 e03dbc90
......@@ -69,6 +69,7 @@ None yet.
XXXX-XX-XX, v1.0.2
------------------
- closed [#373](https://github.com/n1k0/casperjs/issues/373) - added RegExp support to `Casper.waitForText()`
- fixed [#368](https://github.com/n1k0/casperjs/issues/368) - Remote JS error is thrown when a click target is missing after `click()`
- merged PR [#357](https://github.com/n1k0/casperjs/pull/357) - fire the `input` event after setting input value (required to support [angular.js](http://angularjs.org/) apps)
......
......@@ -1837,20 +1837,24 @@ Casper.prototype.waitForSelector = function waitForSelector(selector, then, onTi
};
/**
* Waits until the page contains given HTML text.
* Waits until the page contains given HTML text or matches a given RegExp.
*
* @param String text Text to wait for
* @param String|RegExp pattern Text or RegExp to wait for
* @param Function then The next step to perform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @param Number timeout The max amount of time to wait, in milliseconds (optional)
* @return Casper
*/
Casper.prototype.waitForText = function(text, then, onTimeout, timeout) {
Casper.prototype.waitForText = function(pattern, then, onTimeout, timeout) {
"use strict";
this.checkStarted();
timeout = timeout ? timeout : this.options.waitTimeout;
return this.waitFor(function _check() {
return this.getPageContent().indexOf(text) !== -1;
var content = this.getPageContent();
if (utils.isRegExp(pattern)) {
return pattern.test(content);
}
return content.indexOf(pattern) !== -1;
}, then, onTimeout, timeout);
};
......
......@@ -425,6 +425,18 @@ function isObject(value) {
exports.isObject = isObject;
/**
* Checks if value is a RegExp
*
* @param mixed value
* @return Boolean
*/
function isRegExp(value) {
"use strict";
return isType(value, "regexp");
}
exports.isRegExp = isRegExp;
/**
* Checks if value is a javascript String
*
* @param mixed value
......
/*global casper*/
/*jshint strict:false*/
casper.test.begin('wait*() tests', 3, function(test) {
casper.test.begin('wait*() tests', 4, function(test) {
var waitStart;
casper.start('tests/site/index.html', function() {
......@@ -30,6 +30,12 @@ casper.test.begin('wait*() tests', 3, function(test) {
test.fail('Casper.waitForText() can wait for text');
});
casper.thenOpen('tests/site/waitFor.html').waitForText(/four/i, function() {
this.test.pass('Casper.waitForText() can wait for regexp');
}, function() {
this.test.fail('Casper.waitForText() can wait for regexp');
});
casper.run(function() {
test.done();
});
......