fixed tests for phantomjs < 1.6
Showing
3 changed files
with
22 additions
and
10 deletions
... | @@ -221,6 +221,9 @@ Casper.prototype.base64encode = function base64encode(url, method, data) { | ... | @@ -221,6 +221,9 @@ Casper.prototype.base64encode = function base64encode(url, method, data) { |
221 | */ | 221 | */ |
222 | Casper.prototype.capture = function capture(targetFile, clipRect) { | 222 | Casper.prototype.capture = function capture(targetFile, clipRect) { |
223 | "use strict"; | 223 | "use strict"; |
224 | if (!this.started) { | ||
225 | throw new CasperError("Casper not started, can't capture()"); | ||
226 | } | ||
224 | var previousClipRect; | 227 | var previousClipRect; |
225 | targetFile = fs.absolute(targetFile); | 228 | targetFile = fs.absolute(targetFile); |
226 | if (clipRect) { | 229 | if (clipRect) { |
... | @@ -258,6 +261,13 @@ Casper.prototype.capture = function capture(targetFile, clipRect) { | ... | @@ -258,6 +261,13 @@ Casper.prototype.capture = function capture(targetFile, clipRect) { |
258 | */ | 261 | */ |
259 | Casper.prototype.captureBase64 = function captureBase64(format, area) { | 262 | Casper.prototype.captureBase64 = function captureBase64(format, area) { |
260 | "use strict"; | 263 | "use strict"; |
264 | if (!this.started) { | ||
265 | throw new CasperError("Casper not started, can't captureBase64()"); | ||
266 | } | ||
267 | if (!('renderBase64' in this.page)) { | ||
268 | this.warn('captureBase64() requires PhantomJS >= 1.6'); | ||
269 | return; | ||
270 | } | ||
261 | var base64; | 271 | var base64; |
262 | var previousClipRect; | 272 | var previousClipRect; |
263 | var formats = ['bmp', 'jpg', 'jpeg', 'png', 'ppm', 'tiff', 'xbm', 'xpm']; | 273 | var formats = ['bmp', 'jpg', 'jpeg', 'png', 'ppm', 'tiff', 'xbm', 'xpm']; | ... | ... |
... | @@ -11,15 +11,17 @@ casper.start('tests/site/index.html', function() { | ... | @@ -11,15 +11,17 @@ casper.start('tests/site/index.html', function() { |
11 | this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); | 11 | this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); |
12 | }); | 12 | }); |
13 | 13 | ||
14 | casper.thenOpen('tests/site/index.html', function() { | 14 | if (phantom.version.major === 1 && phantom.version.minor >= 6) { |
15 | this.test.comment('Casper.captureBase64()'); | 15 | casper.thenOpen('tests/site/index.html', function() { |
16 | this.test.assert(this.captureBase64('png').length > 0, | 16 | this.test.comment('Casper.captureBase64()'); |
17 | 'Casper.captureBase64() rendered a page capture as base64'); | 17 | this.test.assert(this.captureBase64('png').length > 0, |
18 | this.test.assert(this.captureBase64('png', 'ul').length > 0, | 18 | 'Casper.captureBase64() rendered a page capture as base64'); |
19 | 'Casper.captureBase64() rendered a capture from a selector as base64'); | 19 | this.test.assert(this.captureBase64('png', 'ul').length > 0, |
20 | this.test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0, | 20 | 'Casper.captureBase64() rendered a capture from a selector as base64'); |
21 | 'Casper.captureBase64() rendered a capture from a clipRect as base64'); | 21 | this.test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0, |
22 | }); | 22 | 'Casper.captureBase64() rendered a capture from a clipRect as base64'); |
23 | }); | ||
24 | } | ||
23 | 25 | ||
24 | casper.run(function() { | 26 | casper.run(function() { |
25 | try { | 27 | try { | ... | ... |
-
Please register or sign in to post a comment