Merge branch 'feature/waitForSelectorTextChange' of http://github.com/PhilipHansen/casperjs
Merged #351 Conflicts: docs tests/suites/casper/wait.js
Showing
3 changed files
with
40 additions
and
2 deletions
... | @@ -1883,6 +1883,26 @@ Casper.prototype.waitForText = function(pattern, then, onTimeout, timeout) { | ... | @@ -1883,6 +1883,26 @@ Casper.prototype.waitForText = function(pattern, then, onTimeout, timeout) { |
1883 | }; | 1883 | }; |
1884 | 1884 | ||
1885 | /** | 1885 | /** |
1886 | * Waits until the text on an element matching the provided DOM CSS3/XPath selector | ||
1887 | * is changed to a different value. | ||
1888 | * | ||
1889 | * @param String selector A DOM CSS3/XPath selector | ||
1890 | * @param Function then The next step to preform (optional) | ||
1891 | * @param Function onTimeout A callback function to call on timeout (optional) | ||
1892 | * @param Number timeout The max amount of time to wait, in milliseconds (optional) | ||
1893 | * @return Casper | ||
1894 | */ | ||
1895 | Casper.prototype.waitForSelectorTextChange = function(selector, then, onTimeout, timeout) { | ||
1896 | "user strict"; | ||
1897 | this.checkStarted(); | ||
1898 | timeout = timeout ? timeout : this.options.waitTimeout; | ||
1899 | var currentSelectorText = this.fetchText(selector); | ||
1900 | return this.waitFor(function _check() { | ||
1901 | return currentSelectorText != this.fetchText(selector); | ||
1902 | }, then, onTimeout, timeout); | ||
1903 | }; | ||
1904 | |||
1905 | /** | ||
1886 | * Waits until an element matching the provided DOM CSS3/XPath selector does not | 1906 | * Waits until an element matching the provided DOM CSS3/XPath selector does not |
1887 | * exist in the remote DOM to process a next step. | 1907 | * exist in the remote DOM to process a next step. |
1888 | * | 1908 | * | ... | ... |
... | @@ -11,11 +11,15 @@ | ... | @@ -11,11 +11,15 @@ |
11 | <li>two</li> | 11 | <li>two</li> |
12 | <li>three</li> | 12 | <li>three</li> |
13 | </ul> | 13 | </ul> |
14 | <div id="textChange" > | ||
15 | Loading... | ||
16 | </div> | ||
14 | <script> | 17 | <script> |
15 | setTimeout(function() { | 18 | setTimeout(function() { |
16 | var li = document.createElement('li') | 19 | var li = document.createElement('li') |
17 | li.appendChild(document.createTextNode('four')); | 20 | li.appendChild(document.createTextNode('four')); |
18 | document.querySelector('ul').appendChild(li); | 21 | document.querySelector('ul').appendChild(li); |
22 | document.getElementById('textChange').innerHTML = 'Done'; | ||
19 | }, 500); | 23 | }, 500); |
20 | </script> | 24 | </script> |
21 | </body> | 25 | </body> | ... | ... |
... | @@ -87,9 +87,23 @@ casper.test.begin('waitForText() tests', 2, function(test) { | ... | @@ -87,9 +87,23 @@ casper.test.begin('waitForText() tests', 2, function(test) { |
87 | }); | 87 | }); |
88 | 88 | ||
89 | casper.reload().waitForText(/four/i, function() { | 89 | casper.reload().waitForText(/four/i, function() { |
90 | this.test.pass('Casper.waitForText() can wait for regexp'); | 90 | test.pass('Casper.waitForText() can wait for regexp'); |
91 | }, function() { | 91 | }, function() { |
92 | this.test.fail('Casper.waitForText() can wait for regexp'); | 92 | test.fail('Casper.waitForText() can wait for regexp'); |
93 | }); | ||
94 | |||
95 | casper.run(function() { | ||
96 | test.done(); | ||
97 | }); | ||
98 | }); | ||
99 | |||
100 | casper.test.begin('waitForSelectorTextChange() tests', 1, function(test) { | ||
101 | casper.start('tests/site/waitFor.html'); | ||
102 | |||
103 | casper.waitForSelectorTextChange('#textChange', function() { | ||
104 | test.pass('Casper.waitForSelectorTextChange() can wait for text on a selector to change'); | ||
105 | }, function() { | ||
106 | test.fail('Casper.waitForSelectorTextChange() can wait for text on a selector to change'); | ||
93 | }); | 107 | }); |
94 | 108 | ||
95 | casper.run(function() { | 109 | casper.run(function() { | ... | ... |
-
Please register or sign in to post a comment