Commit dfc5d75f dfc5d75fbf6e18fa5f769ace03d765cc77fd0a7a by Nicolas Perriault

Merge branch 'feature/waitForSelectorTextChange' of http://github.com/PhilipHansen/casperjs

Merged #351

Conflicts:
	docs
	tests/suites/casper/wait.js
2 parents 3f1d2a39 730e75be
......@@ -1883,6 +1883,26 @@ Casper.prototype.waitForText = function(pattern, then, onTimeout, timeout) {
};
/**
* Waits until the text on an element matching the provided DOM CSS3/XPath selector
* is changed to a different value.
*
* @param String selector A DOM CSS3/XPath selector
* @param Function then The next step to preform (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.waitForSelectorTextChange = function(selector, then, onTimeout, timeout) {
"user strict";
this.checkStarted();
timeout = timeout ? timeout : this.options.waitTimeout;
var currentSelectorText = this.fetchText(selector);
return this.waitFor(function _check() {
return currentSelectorText != this.fetchText(selector);
}, 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.
*
......
......@@ -11,11 +11,15 @@
<li>two</li>
<li>three</li>
</ul>
<div id="textChange" >
Loading...
</div>
<script>
setTimeout(function() {
var li = document.createElement('li')
li.appendChild(document.createTextNode('four'));
document.querySelector('ul').appendChild(li);
document.getElementById('textChange').innerHTML = 'Done';
}, 500);
</script>
</body>
......
......@@ -87,9 +87,23 @@ casper.test.begin('waitForText() tests', 2, function(test) {
});
casper.reload().waitForText(/four/i, function() {
this.test.pass('Casper.waitForText() can wait for regexp');
test.pass('Casper.waitForText() can wait for regexp');
}, function() {
this.test.fail('Casper.waitForText() can wait for regexp');
test.fail('Casper.waitForText() can wait for regexp');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForSelectorTextChange() tests', 1, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitForSelectorTextChange('#textChange', function() {
test.pass('Casper.waitForSelectorTextChange() can wait for text on a selector to change');
}, function() {
test.fail('Casper.waitForSelectorTextChange() can wait for text on a selector to change');
});
casper.run(function() {
......