2017-01-12 05:08:59 +00:00
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var phantomcss = require('phantomcss');
|
|
|
|
|
2017-02-05 00:42:31 +00:00
|
|
|
casper.test.begin('jspaint visual tests', function(test){
|
|
|
|
|
|
|
|
phantomcss.init({
|
|
|
|
rebase: casper.cli.get('rebase'),
|
2017-01-12 05:08:59 +00:00
|
|
|
// SlimerJS needs explicit knowledge of this Casper, and lots of absolute paths
|
|
|
|
casper: casper,
|
2017-02-05 00:42:31 +00:00
|
|
|
libraryRoot: fs.absolute(fs.workingDirectory + '/node_modules/phantomcss'), //module._getFilename('phantomcss'), //require.resolve('phantomcss'),
|
|
|
|
screenshotRoot: fs.absolute(fs.workingDirectory + '/screenshots'),
|
|
|
|
failedComparisonsRoot: fs.absolute(fs.workingDirectory + '/screenshots/failures'),
|
2017-01-12 05:08:59 +00:00
|
|
|
addLabelToFailedImage: false,
|
|
|
|
/*
|
|
|
|
fileNameGetter: function overide_file_naming(){},
|
2017-02-05 00:42:31 +00:00
|
|
|
onPass: function pass_callback(){},
|
|
|
|
onFail: function fail_callback(){},
|
|
|
|
onTimeout: function timeout_callback(){},
|
|
|
|
onComplete: function complete_callback(){},
|
2017-01-12 05:08:59 +00:00
|
|
|
hideElements: '#thing.selector',
|
|
|
|
addLabelToFailedImage: true,
|
|
|
|
outputSettings: {
|
|
|
|
errorColor: {
|
|
|
|
red: 255,
|
|
|
|
green: 255,
|
|
|
|
blue: 0
|
|
|
|
},
|
|
|
|
errorType: 'movement',
|
|
|
|
transparency: 0.3
|
|
|
|
}*/
|
2017-02-05 00:42:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.on('remote.message', function(msg){
|
|
|
|
this.echo("[page] " + 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');
|
|
|
|
});
|
2017-01-12 05:08:59 +00:00
|
|
|
/*
|
|
|
|
The test scenario
|
|
|
|
*/
|
|
|
|
|
2017-02-05 00:42:31 +00:00
|
|
|
casper.start('http://localhost:11822');
|
|
|
|
|
|
|
|
casper.viewport(1024, 768);
|
|
|
|
|
|
|
|
casper.then(function(){
|
|
|
|
phantomcss.screenshot('.jspaint', 'app screen initial');
|
2017-05-23 06:04:23 +00:00
|
|
|
phantomcss.screenshot('.menus', 'menu bar initial');
|
|
|
|
phantomcss.screenshot('.Tools-component', 'toolbox initial');
|
|
|
|
phantomcss.screenshot('.Colors-component', 'color box initial');
|
2017-02-05 00:42:31 +00:00
|
|
|
});
|
2017-01-12 05:08:59 +00:00
|
|
|
|
2017-02-05 00:33:59 +00:00
|
|
|
var screenshot_and_close_window = function(screenshot_name){
|
|
|
|
// var window_title = "Attributes";
|
|
|
|
// var selector = {
|
|
|
|
// type: "xpath",
|
2017-05-23 06:04:23 +00:00
|
|
|
// path: "//div[contains(concat(' ', normalize-space(@class), ' '), ' window ')][//span[contains(concat(' ', normalize-space(@class), ' '), ' window-title ')][.='" + window_title + "']]"
|
2017-02-05 00:33:59 +00:00
|
|
|
// };
|
2017-05-23 06:04:23 +00:00
|
|
|
var selector = ".window:not([style*='display: none'])";
|
2017-02-04 20:29:39 +00:00
|
|
|
|
2017-02-05 00:33:59 +00:00
|
|
|
casper.then(function(){
|
2017-02-05 00:42:31 +00:00
|
|
|
casper.waitUntilVisible(selector,
|
|
|
|
function success(){
|
|
|
|
phantomcss.screenshot(selector, screenshot_name);
|
2017-02-05 00:33:59 +00:00
|
|
|
}
|
|
|
|
);
|
2017-02-05 00:42:31 +00:00
|
|
|
});
|
|
|
|
// casper.thenEvaluate(function(selector){
|
2017-05-23 06:04:23 +00:00
|
|
|
// $(selector).find(".window-close-button").click();
|
2017-02-05 00:33:59 +00:00
|
|
|
// }, selector);
|
2017-02-05 00:42:31 +00:00
|
|
|
casper.then(function close_the_window(){
|
2017-05-23 06:04:23 +00:00
|
|
|
casper.click(selector + " .window-close-button");
|
2017-02-05 00:42:31 +00:00
|
|
|
});
|
2017-02-05 00:33:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
casper.thenEvaluate(function(){
|
|
|
|
image_attributes();
|
|
|
|
});
|
|
|
|
screenshot_and_close_window('attributes window');
|
|
|
|
|
|
|
|
casper.thenEvaluate(function(){
|
|
|
|
image_flip_and_rotate();
|
|
|
|
});
|
|
|
|
screenshot_and_close_window('flip and rotate window');
|
|
|
|
|
|
|
|
casper.thenEvaluate(function(){
|
|
|
|
image_stretch_and_skew();
|
|
|
|
});
|
|
|
|
screenshot_and_close_window('stretch and skew window');
|
|
|
|
|
|
|
|
casper.thenEvaluate(function(){
|
|
|
|
show_help();
|
|
|
|
});
|
|
|
|
screenshot_and_close_window('help window');
|
|
|
|
|
2017-02-05 00:42:31 +00:00
|
|
|
casper.then(function now_check_the_screenshots(){
|
2017-01-12 05:08:59 +00:00
|
|
|
phantomcss.compareAll();
|
2017-02-05 00:42:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.run(function(){
|
|
|
|
console.log('\nTHE END.');
|
2017-01-12 05:08:59 +00:00
|
|
|
// phantomcss.getExitStatus() // pass or fail?
|
|
|
|
casper.test.done();
|
2017-02-05 00:42:31 +00:00
|
|
|
});
|
|
|
|
});
|