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 ...@@ -7,6 +7,7 @@ XXXX-XX-XX, v1.0.0
7 This version is yet to be released. 7 This version is yet to be released.
8 8
9 - fixed [#259](https://github.com/n1k0/casperjs/issues/259) - enhanced `Tester.assertField()` method, which can now tests for other field types than `input`s. 9 - fixed [#259](https://github.com/n1k0/casperjs/issues/259) - enhanced `Tester.assertField()` method, which can now tests for other field types than `input`s.
10 - added [`Casper.waitForText()`](http://casperjs.org/api.html#casper.waitForText) to wait for a given text to be present in page HTML contents
10 - added [`ClientUtils.getFieldValue()`](http://casperjs.org/api.html#clientutils.getFieldValue) 11 - added [`ClientUtils.getFieldValue()`](http://casperjs.org/api.html#clientutils.getFieldValue)
11 12
12 2012-10-23, v1.0.0-RC3 13 2012-10-23, v1.0.0-RC3
......
1 Subproject commit 3b87b13e5849f5c8d7555c9a5fc6712eda5aa7a8 1 Subproject commit 559c683105a2b35c172723d7510e33f42180dfca
......
...@@ -1654,6 +1654,24 @@ Casper.prototype.waitForSelector = function waitForSelector(selector, then, onTi ...@@ -1654,6 +1654,24 @@ Casper.prototype.waitForSelector = function waitForSelector(selector, then, onTi
1654 }; 1654 };
1655 1655
1656 /** 1656 /**
1657 * Waits until the page contains given HTML text.
1658 *
1659 * @param String text Text to wait for
1660 * @param Function then The next step to perform (optional)
1661 * @param Function onTimeout A callback function to call on timeout (optional)
1662 * @param Number timeout The max amount of time to wait, in milliseconds (optional)
1663 * @return Casper
1664 */
1665 Casper.prototype.waitForText = function(text, then, onTimeout, timeout) {
1666 "use strict";
1667 this.checkStarted();
1668 timeout = timeout ? timeout : this.options.waitTimeout;
1669 return this.waitFor(function _check() {
1670 return this.getPageContent().indexOf(text) !== -1;
1671 }, then, onTimeout, timeout);
1672 };
1673
1674 /**
1657 * Waits until an element matching the provided DOM CSS3/XPath selector does not 1675 * Waits until an element matching the provided DOM CSS3/XPath selector does not
1658 * exist in the remote DOM to process a next step. 1676 * exist in the remote DOM to process a next step.
1659 * 1677 *
......
1 /*global casper*/
2 /*jshint strict:false*/
1 var waitStart; 3 var waitStart;
2 4
3 casper.start('tests/site/index.html', function() { 5 casper.start('tests/site/index.html', function() {
...@@ -22,6 +24,14 @@ casper.wait(1000, function() { ...@@ -22,6 +24,14 @@ casper.wait(1000, function() {
22 }); 24 });
23 }); 25 });
24 26
27 casper.thenOpen('tests/site/waitFor.html').waitForText('<li>four</li>', function() {
28 this.test.comment('Casper.waitForText()');
29 this.test.pass('Casper.waitForText() can wait for text');
30 }, function() {
31 this.test.comment('Casper.waitForText()');
32 this.test.fail('Casper.waitForText() can wait for text');
33 });
34
25 casper.run(function() { 35 casper.run(function() {
26 this.test.done(); 36 this.test.done();
27 }); 37 });
......