Skip to content

Commit dec279e

Browse files
committed
started adding visual regression testing using PhantomCSS
1 parent 4297bb5 commit dec279e

5 files changed

Lines changed: 846 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all:
2+
casperjs test opt-visualize-html-test.js
3+
4+
clean:
5+
rm -rf screenshots/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
We will use phantomcss.js for visual regression testing of the OPT
2+
frontend
3+
4+
First install PhantomJS (e.g., for Mac) by downloading a binary:
5+
http://phantomjs.org/download.html
6+
7+
and adding it to $PATH so that the 'phantomjs' executable works
8+
9+
Then install CasperJS globally:
10+
sudo npm install -g casperjs
11+
12+
Now the 'phantomjs' and 'casperjs' commands should both work
13+
14+
15+
Then install resemblejs locally:
16+
npm install resemblejs
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Visually test visualize.html on localhost
2+
var htmlPath = "http://localhost:8003/visualize.html"
3+
4+
var fs = require('fs');
5+
var path = fs.absolute(fs.workingDirectory + '/phantomcss.js');
6+
var phantomcss = require(path);
7+
8+
casper.test.begin('Testing ' + htmlPath, function (test) {
9+
// boring setup code taken from PhantomCSS demo
10+
phantomcss.init({
11+
rebase: casper.cli.get( "rebase" ),
12+
// SlimerJS needs explicit knowledge of this Casper, and lots of absolute paths
13+
casper: casper,
14+
libraryRoot: fs.absolute( fs.workingDirectory + '' ),
15+
screenshotRoot: fs.absolute( fs.workingDirectory + '/screenshots' ),
16+
failedComparisonsRoot: fs.absolute( fs.workingDirectory + '/demo/failures' ),
17+
addLabelToFailedImage: false,
18+
});
19+
20+
casper.on('remote.message', function(msg) {this.echo(msg);});
21+
casper.on('error', function (err) {this.die( "PhantomJS has errored: " + err );});
22+
casper.on('resource.error', function (err) {casper.log( 'Resource load error: ' + err, 'warning' );});
23+
24+
25+
casper.start(htmlPath);
26+
casper.viewport(1440, 900, function () {
27+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
28+
});
29+
30+
// click on one example code for each language
31+
casper.then(function() {
32+
casper.click("#aliasExampleLink");
33+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
34+
});
35+
36+
casper.then(function() {
37+
casper.click("#tortureLink");
38+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
39+
});
40+
41+
casper.then(function() {
42+
casper.click("#javaVarLink");
43+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
44+
});
45+
46+
casper.then(function() {
47+
casper.click("#jsDatatypesExLink");
48+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
49+
});
50+
51+
casper.then(function() {
52+
casper.click("#tsGreeterExLink");
53+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
54+
});
55+
56+
casper.then(function() {
57+
casper.click("#rubyConstantsLink");
58+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
59+
});
60+
61+
casper.then(function() {
62+
casper.click("#cMengThesisLink");
63+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
64+
});
65+
66+
casper.then(function() {
67+
casper.click("#cppFirstLink");
68+
phantomcss.screenshot('#pyInputPane', 'pyInputPane');
69+
});
70+
71+
72+
// run all the tests:
73+
casper.then(function now_check_the_screenshots() {
74+
phantomcss.compareAll(); // compare screenshots
75+
});
76+
77+
casper.run(function() {
78+
//phantomcss.getExitStatus() // pass or fail?
79+
casper.test.done();
80+
});
81+
});

0 commit comments

Comments
 (0)