Commit 656f2d10 656f2d103b0ee40202032447cf5b4707ff2eaa23 by Philip Hansen

refs #350 - Added method and tests for waitForSelectorTextChange()

1 parent 6ea9a841
......@@ -1852,6 +1852,26 @@ Casper.prototype.waitForText = function(text, 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>
......
/*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').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() {
test.done();
});
......