Commit c816b83e c816b83e9e110b1c0e34959da8eab5f128a2c4e5 by Nicolas Perriault

added Casper.waitForText()

to wait for a given text to be present in page HTML contents
1 parent 3ddea2a4
......@@ -7,6 +7,7 @@ XXXX-XX-XX, v1.0.0
This version is yet to be released.
- fixed [#259](https://github.com/n1k0/casperjs/issues/259) - enhanced `Tester.assertField()` method, which can now tests for other field types than `input`s.
- added [`Casper.waitForText()`](http://casperjs.org/api.html#casper.waitForText) to wait for a given text to be present in page HTML contents
- added [`ClientUtils.getFieldValue()`](http://casperjs.org/api.html#clientutils.getFieldValue)
2012-10-23, v1.0.0-RC3
......
Subproject commit 3b87b13e5849f5c8d7555c9a5fc6712eda5aa7a8
Subproject commit 559c683105a2b35c172723d7510e33f42180dfca
......
......@@ -1654,6 +1654,24 @@ Casper.prototype.waitForSelector = function waitForSelector(selector, then, onTi
};
/**
* Waits until the page contains given HTML text.
*
* @param String text Text 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) {
"use strict";
this.checkStarted();
timeout = timeout ? timeout : this.options.waitTimeout;
return this.waitFor(function _check() {
return this.getPageContent().indexOf(text) !== -1;
}, then, onTimeout, timeout);
};
/**
* Waits until an element matching the provided DOM CSS3/XPath selector does not
* exist in the remote DOM to process a next step.
*
......
/*global casper*/
/*jshint strict:false*/
var waitStart;
casper.start('tests/site/index.html', function() {
......@@ -22,6 +24,14 @@ casper.wait(1000, function() {
});
});
casper.thenOpen('tests/site/waitFor.html').waitForText('<li>four</li>', function() {
this.test.comment('Casper.waitForText()');
this.test.pass('Casper.waitForText() can wait for text');
}, function() {
this.test.comment('Casper.waitForText()');
this.test.fail('Casper.waitForText() can wait for text');
});
casper.run(function() {
this.test.done();
});
......