|
| 1 | +// Run a visual regression test on htmlPath, putting outputs in outputDir |
| 2 | +var htmlPath = "http://localhost:8003/embedding-demo.html" |
| 3 | +var outputDir = "/test-embedding-demo-outputs" |
| 4 | + |
| 5 | +var DELAY_MS = 100; |
| 6 | + |
| 7 | +var fs = require('fs'); |
| 8 | +var path = fs.absolute(fs.workingDirectory + '/phantomcss.js'); |
| 9 | +var phantomcss = require(path); |
| 10 | + |
| 11 | +casper.test.begin('Testing ' + htmlPath, function (test) { |
| 12 | + // boring setup code taken from PhantomCSS demo |
| 13 | + phantomcss.init({ |
| 14 | + rebase: casper.cli.get( "rebase" ), |
| 15 | + // SlimerJS needs explicit knowledge of this Casper, and lots of absolute paths |
| 16 | + casper: casper, |
| 17 | + libraryRoot: fs.absolute( fs.workingDirectory + '' ), |
| 18 | + screenshotRoot: fs.absolute( fs.workingDirectory + outputDir + '/screenshots' ), |
| 19 | + failedComparisonsRoot: fs.absolute( fs.workingDirectory + outputDir + '/failures' ), |
| 20 | + addLabelToFailedImage: false, |
| 21 | + }); |
| 22 | + |
| 23 | + casper.on('remote.message', function(msg) {this.echo(msg);}); |
| 24 | + casper.on('error', function (err) {this.die( "PhantomJS has errored: " + err );}); |
| 25 | + casper.on('resource.error', function (err) {casper.log( 'Resource load error: ' + err, 'warning' );}); |
| 26 | + |
| 27 | + |
| 28 | + // start with a baseline image |
| 29 | + casper.start(htmlPath); |
| 30 | + casper.viewport(1440, 900, function () { |
| 31 | + casper.waitFor(function check() { |
| 32 | + return this.evaluate(function() { |
| 33 | + return document.querySelectorAll("#happyDiv #dataViz").length > 0; |
| 34 | + }); |
| 35 | + }, function then() { |
| 36 | + this.wait(DELAY_MS, function() { |
| 37 | + phantomcss.screenshot('body', 'embedding-demo-page'); |
| 38 | + }); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + |
| 43 | + // run all tests: |
| 44 | + casper.then(function now_check_the_screenshots() { |
| 45 | + phantomcss.compareAll(); // compare screenshots |
| 46 | + }); |
| 47 | + |
| 48 | + casper.run(function() { |
| 49 | + //phantomcss.getExitStatus() // pass or fail? |
| 50 | + casper.test.done(); |
| 51 | + }); |
| 52 | +}); |
0 commit comments