Blame view

tests/suites/casper/capture.js 1.49 KB
1 2
/*global casper*/
/*jshint strict:false*/
3
var fs = require('fs');
4

5 6
casper.test.begin('Casper.capture() tests', 1, {
    testFile: '/tmp/__casper_test_capture.png',
7

8 9 10 11 12 13 14 15 16 17
    setUp: function(test) {
        if (fs.exists(this.testFile) && fs.isFile(this.testFile)) {
            try {
                fs.remove(this.testFile);
            } catch (e) {
            }
        }
    },

    tearDown: function(test) {
18
        try {
19
            fs.remove(this.testFile);
20 21
        } catch(e) {
        }
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    },

    test: function(test) {
        var self = this;

        casper.start('tests/site/index.html', function() {
            this.viewport(300, 200);
            this.capture(self.testFile);
            test.assert(fs.isFile(self.testFile), 'Casper.capture() captured a screenshot');
        });

        casper.run(function() {
            test.done();
        });
    }
37
});
38

39 40 41
casper.test.begin('Casper.captureBase64() tests', 3, function(test) {
    casper.start('tests/site/index.html', function() {
        test.assert(this.captureBase64('png').length > 0,
42
            'Casper.captureBase64() rendered a page capture as base64');
43
        test.assert(this.captureBase64('png', 'ul').length > 0,
44
            'Casper.captureBase64() rendered a capture from a selector as base64');
45
        test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0,
46
            'Casper.captureBase64() rendered a capture from a clipRect as base64');
47 48 49
    }).run(function() {
        test.done();
    });
50
});