Last active
September 29, 2016 04:35
-
-
Save HeikoMamerow/95e735c93304bfe2b892 to your computer and use it in GitHub Desktop.
Template for CSS regression test with Phantomcss over multiple sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is my default template for a test with PhantomCSS | |
/* | |
Require and initialise PhantomCSS module | |
Paths are relative to CasperJs directory | |
*/ | |
var fs = require( 'fs' ); | |
var path = fs.absolute( fs.workingDirectory + '/phantomcss.js' ); | |
var phantomcss = require( path ); | |
casper.test.begin( 'test title', function ( test ) { | |
phantomcss.init( { | |
rebase: casper.cli.get( "rebase" ), | |
// SlimerJS needs explicit knowledge of this Casper, and lots of absolute paths | |
casper: casper, | |
libraryRoot: fs.absolute( fs.workingDirectory + '' ), | |
screenshotRoot: fs.absolute( fs.workingDirectory + '/test/screenshots' ), | |
failedComparisonsRoot: fs.absolute( fs.workingDirectory + '/test/failures' ), | |
addLabelToFailedImage: false, | |
} ); | |
casper.on( 'remote.message', function ( msg ) { | |
this.echo( msg ); | |
} ) | |
casper.on( 'error', function ( err ) { | |
this.die( "PhantomJS has errored: " + err ); | |
} ); | |
casper.on( 'resource.error', function ( err ) { | |
casper.log( 'Resource load error: ' + err, 'warning' ); | |
} ); | |
// Take screenshots of these sites | |
var links = [ | |
"http://webwork/clients/local-test/wordpress", | |
"http://webwork/clients/local-test/wordpress/about1.htm", | |
"http://webwork/clients/local-test/wordpress/products.htm" | |
]; | |
casper.start(); | |
var i = 0; | |
casper.each(links, function(self, link) { | |
this.thenOpen(link, function() { | |
i++; | |
/* | |
The test scenario | |
*/ | |
casper.viewport( 1024, 768 ); | |
casper.then( function () { | |
phantomcss.screenshot( 'body', 'Body' ); | |
} ); | |
casper.then( function now_check_the_screenshots() { | |
// compare screenshots | |
phantomcss.compareAll(); | |
} ); | |
}); | |
}); | |
/* | |
Casper runs tests | |
*/ | |
casper.run( function () { | |
console.log( '\nTHE END.' ); | |
// phantomcss.getExitStatus() // pass or fail? | |
casper.test.done(); | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment