Blame view

tests/suites/casper/capture.js 1.21 KB
1 2
/*global casper*/
/*jshint strict:false*/
3
var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png';
4

5 6 7
if (fs.exists(testFile) && fs.isFile(testFile)) {
    fs.remove(testFile);
}
8

9 10
casper.start('tests/site/index.html', function() {
    this.viewport(300, 200);
11
    this.test.comment('Casper.capture()');
12
    this.capture(testFile);
13 14
    this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot');
});
15

16 17 18 19 20 21 22 23 24 25 26
if (phantom.version.major === 1 && phantom.version.minor >= 6) {
    casper.thenOpen('tests/site/index.html', function() {
        this.test.comment('Casper.captureBase64()');
        this.test.assert(this.captureBase64('png').length > 0,
                         'Casper.captureBase64() rendered a page capture as base64');
        this.test.assert(this.captureBase64('png', 'ul').length > 0,
                         'Casper.captureBase64() rendered a capture from a selector as base64');
        this.test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0,
                         'Casper.captureBase64() rendered a capture from a clipRect as base64');
    });
}
27

28 29 30 31
casper.run(function() {
    try {
        fs.remove(testFile);
    } catch(e) {}
32 33
    this.test.done();
});