forked from 1j01/jspaint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
112 lines (95 loc) · 3.1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var fs = require('fs');
var phantomcss = require('phantomcss');
casper.test.begin('jspaint visual tests', 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 + '/node_modules/phantomcss'), //module._getFilename('phantomcss'), //require.resolve('phantomcss'),
screenshotRoot: fs.absolute(fs.workingDirectory + '/screenshots'),
failedComparisonsRoot: fs.absolute(fs.workingDirectory + '/screenshots/failures'),
addLabelToFailedImage: false,
/*
fileNameGetter: function overide_file_naming(){},
onPass: function pass_callback(){},
onFail: function fail_callback(){},
onTimeout: function timeout_callback(){},
onComplete: function complete_callback(){},
hideElements: '#thing.selector',
addLabelToFailedImage: true,
outputSettings: {
errorColor: {
red: 255,
green: 255,
blue: 0
},
errorType: 'movement',
transparency: 0.3
}*/
});
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');
});
/*
The test scenario
*/
casper.start('http://localhost:11822');
casper.viewport(1024, 768);
casper.then(function(){
phantomcss.screenshot('.jspaint', 'app screen initial');
phantomcss.screenshot('.menus', 'menu bar initial');
phantomcss.screenshot('.Tools-component', 'toolbox initial');
phantomcss.screenshot('.Colors-component', 'color box initial');
});
var screenshot_and_close_window = function(screenshot_name){
// var window_title = "Attributes";
// var selector = {
// type: "xpath",
// path: "//div[contains(concat(' ', normalize-space(@class), ' '), ' window ')][//span[contains(concat(' ', normalize-space(@class), ' '), ' window-title ')][.='" + window_title + "']]"
// };
var selector = ".window:not([style*='display: none'])";
casper.then(function(){
casper.waitUntilVisible(selector,
function success(){
phantomcss.screenshot(selector, screenshot_name);
}
);
});
// casper.thenEvaluate(function(selector){
// $(selector).find(".window-close-button").click();
// }, selector);
casper.then(function close_the_window(){
casper.click(selector + " .window-close-button");
});
};
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');
casper.then(function now_check_the_screenshots(){
phantomcss.compareAll();
});
casper.run(function(){
console.log('\nTHE END.');
// phantomcss.getExitStatus() // pass or fail?
casper.test.done();
});
});