Merge branch 'master' of github.com:n1k0/casperjs into request-changeurl
Showing
16 changed files
with
63 additions
and
25 deletions
... | @@ -3,7 +3,7 @@ branches: | ... | @@ -3,7 +3,7 @@ branches: |
3 | - "master" | 3 | - "master" |
4 | - "1.0" | 4 | - "1.0" |
5 | before_script: | 5 | before_script: |
6 | - "npm install -g jshint@0.9.1" | 6 | - "npm install -g jshint@1.0.0" |
7 | - "phantomjs --version" | 7 | - "phantomjs --version" |
8 | - "export PHANTOMJS_EXECUTABLE='phantomjs --local-to-remote-url-access=yes --ignore-ssl-errors=yes'" | 8 | - "export PHANTOMJS_EXECUTABLE='phantomjs --local-to-remote-url-access=yes --ignore-ssl-errors=yes'" |
9 | script: | 9 | script: | ... | ... |
... | @@ -28,8 +28,8 @@ | ... | @@ -28,8 +28,8 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global console phantom require*/ | 31 | /*global console, phantom, require:true*/ |
32 | /*jshint maxstatements:30 maxcomplexity:10*/ | 32 | /*jshint maxstatements:30, maxcomplexity:10*/ |
33 | 33 | ||
34 | // phantom check | 34 | // phantom check |
35 | if (!phantom) { | 35 | if (!phantom) { | ... | ... |
... | @@ -56,5 +56,5 @@ CASPER_COMMAND.extend(CASPER_ARGS) | ... | @@ -56,5 +56,5 @@ CASPER_COMMAND.extend(CASPER_ARGS) |
56 | try: | 56 | try: |
57 | os.execvp(CASPER_COMMAND[0], CASPER_COMMAND) | 57 | os.execvp(CASPER_COMMAND[0], CASPER_COMMAND) |
58 | except OSError as err: | 58 | except OSError as err: |
59 | print(('Fatal: %s; did you install phantomjs?' % err)) | 59 | print('Fatal: %s; did you install phantomjs?' % err) |
60 | sys.exit(1) | 60 | sys.exit(1) | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom __utils__ patchRequire*/ | 31 | /*global CasperError, console, exports, phantom, __utils__, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var colorizer = require('colorizer'); | 34 | var colorizer = require('colorizer'); |
... | @@ -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 | "use 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 | * | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom patchRequire*/ | 31 | /*global CasperError, console, exports, phantom, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var utils = require('utils'); | 34 | var utils = require('utils'); | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global console escape exports NodeList window*/ | 31 | /*global console, escape, exports, NodeList, window*/ |
32 | 32 | ||
33 | (function(exports) { | 33 | (function(exports) { |
34 | "use strict"; | 34 | "use strict"; |
... | @@ -76,7 +76,7 @@ | ... | @@ -76,7 +76,7 @@ |
76 | * @return string | 76 | * @return string |
77 | */ | 77 | */ |
78 | this.decode = function decode(str) { | 78 | this.decode = function decode(str) { |
79 | /*jshint maxstatements:30 maxcomplexity:30 */ | 79 | /*jshint maxstatements:30, maxcomplexity:30 */ |
80 | var c1, c2, c3, c4, i = 0, len = str.length, out = ""; | 80 | var c1, c2, c3, c4, i = 0, len = str.length, out = ""; |
81 | while (i < len) { | 81 | while (i < len) { |
82 | do { | 82 | do { | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global exports console patchRequire*/ | 31 | /*global exports, console, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var fs = require('fs'); | 34 | var fs = require('fs'); | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError exports patchRequire*/ | 31 | /*global CasperError, exports, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var utils = require('utils'); | 34 | var utils = require('utils'); | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom patchRequire*/ | 31 | /*global CasperError, console, exports, phantom, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var utils = require('utils'); | 34 | var utils = require('utils'); | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError exports phantom __utils__ patchRequire*/ | 31 | /*global CasperError, exports, phantom, __utils__, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var fs = require('fs'); | 34 | var fs = require('fs'); |
... | @@ -666,13 +666,15 @@ Tester.prototype.assertFalsy = function assertFalsy(subject, message) { | ... | @@ -666,13 +666,15 @@ Tester.prototype.assertFalsy = function assertFalsy(subject, message) { |
666 | Tester.prototype.assertSelectorHasText = | 666 | Tester.prototype.assertSelectorHasText = |
667 | Tester.prototype.assertSelectorContains = function assertSelectorHasText(selector, text, message) { | 667 | Tester.prototype.assertSelectorContains = function assertSelectorHasText(selector, text, message) { |
668 | "use strict"; | 668 | "use strict"; |
669 | var textFound = this.casper.fetchText(selector).indexOf(text) !== -1; | 669 | var got = this.casper.fetchText(selector); |
670 | var textFound = got.indexOf(text) !== -1; | ||
670 | return this.assert(textFound, message, { | 671 | return this.assert(textFound, message, { |
671 | type: "assertSelectorHasText", | 672 | type: "assertSelectorHasText", |
672 | standard: f('Found "%s" within the selector "%s"', text, selector), | 673 | standard: f('Found "%s" within the selector "%s"', text, selector), |
673 | values: { | 674 | values: { |
674 | selector: selector, | 675 | selector: selector, |
675 | text: text | 676 | text: text, |
677 | actualContent: got | ||
676 | } | 678 | } |
677 | }); | 679 | }); |
678 | }; | 680 | }; |
... | @@ -922,7 +924,7 @@ Tester.prototype.comment = function comment(message) { | ... | @@ -922,7 +924,7 @@ Tester.prototype.comment = function comment(message) { |
922 | */ | 924 | */ |
923 | Tester.prototype.done = function done() { | 925 | Tester.prototype.done = function done() { |
924 | "use strict"; | 926 | "use strict"; |
925 | /*jshint maxstatements:20 maxcomplexity:20*/ | 927 | /*jshint maxstatements:20, maxcomplexity:20*/ |
926 | var planned, config = this.currentSuite.config; | 928 | var planned, config = this.currentSuite.config; |
927 | if (utils.isNumber(arguments[0])) { | 929 | if (utils.isNumber(arguments[0])) { |
928 | this.casper.warn('done() `planned` arg is deprecated as of 1.1'); | 930 | this.casper.warn('done() `planned` arg is deprecated as of 1.1'); | ... | ... |
... | @@ -28,7 +28,7 @@ | ... | @@ -28,7 +28,7 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom patchRequire*/ | 31 | /*global CasperError, console, exports, phantom, patchRequire*/ |
32 | 32 | ||
33 | var require = patchRequire(require); | 33 | var require = patchRequire(require); |
34 | var utils = require('utils'); | 34 | var utils = require('utils'); |
... | @@ -166,5 +166,6 @@ XUnitExporter.prototype.setResults = function setResults(results) { | ... | @@ -166,5 +166,6 @@ XUnitExporter.prototype.setResults = function setResults(results) { |
166 | if (!(results instanceof TestSuiteResult)) { | 166 | if (!(results instanceof TestSuiteResult)) { |
167 | throw new CasperError('Invalid results type.'); | 167 | throw new CasperError('Invalid results type.'); |
168 | } | 168 | } |
169 | return this.results = results; | 169 | this.results = results; |
170 | return results; | ||
170 | }; | 171 | }; | ... | ... |
... | @@ -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