wraith 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/{wraith-logo.png → assets/wraith-logo.png} +0 -0
- data/lib/wraith/cli.rb +2 -9
- data/lib/wraith/folder.rb +5 -1
- data/lib/wraith/gallery.rb +11 -1
- data/lib/wraith/gallery_template/gallery_template.erb +3 -0
- data/lib/wraith/version.rb +1 -1
- data/lib/wraith/wraith.rb +1 -1
- data/{configs → spec/configs}/test_config--casper.yaml +6 -1
- data/{configs/test_config.yaml → spec/configs/test_config--phantom.yaml} +6 -1
- data/spec/helpers.rb +6 -2
- data/spec/js/global.js +2 -2
- data/spec/js/path.js +2 -2
- data/spec/thumbnails/test/test_image-1.png +0 -0
- data/spec/thumbnails/test/test_image-2.png +0 -0
- data/spec/thumbnails/test/test_image-diff.png +0 -0
- data/spec/wraith_spec.rb +79 -7
- data/templates/README.md +5 -0
- data/templates/configs/component.yaml +58 -0
- data/templates/configs/multiple_domains.yaml +54 -0
- data/templates/configs/spider.yaml +54 -0
- data/templates/javascript/README.md +5 -0
- data/templates/javascript/_getDimensions.js +7 -0
- data/templates/javascript/_phantom__common.js +122 -0
- data/templates/javascript/beforeCapture--casper_example.js +5 -0
- data/templates/javascript/beforeCapture--phantom_example.js +9 -0
- data/templates/javascript/casper.js +59 -0
- data/templates/javascript/phantom--nojs.js +6 -0
- data/templates/javascript/phantom.js +6 -0
- metadata +26 -17
- data/configs/component.yaml +0 -47
- data/configs/config_nojs.yaml +0 -43
- data/configs/custom_height.yaml +0 -42
- data/configs/history.yaml +0 -52
- data/configs/templates/component.yaml +0 -51
- data/configs/templates/config.yaml +0 -43
- data/lib/wraith/javascript/beforeCapture.js +0 -5
- data/lib/wraith/javascript/casper.js +0 -48
- data/lib/wraith/javascript/customHeight.js +0 -99
- data/lib/wraith/javascript/nojs.js +0 -85
- data/lib/wraith/javascript/snap.js +0 -85
@@ -0,0 +1,5 @@
|
|
1
|
+
These JavaScript files have been provided by Wraith for your benefit, but you are free to edit these or add new JavaScript files if you wish.
|
2
|
+
|
3
|
+
Files beginning with an underscore should not be referenced directly in your YAML files. They are 'private' modules required by some of the other modules in this directory.
|
4
|
+
|
5
|
+
The two most important files to be aware of are `casper.js` and `_phantom__common.js`, as these files map Wraith's command line arguments to each respective browser engine.
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module.exports = function (config) {
|
2
|
+
|
3
|
+
// modules
|
4
|
+
var page = require('webpage').create();
|
5
|
+
|
6
|
+
// config
|
7
|
+
var systemArgs = config.systemArgs,
|
8
|
+
javascriptEnabled = config.javascriptEnabled;
|
9
|
+
|
10
|
+
// command line arguments
|
11
|
+
var url = systemArgs[1],
|
12
|
+
dimensions = require('./_getDimensions.js')(systemArgs[2]),
|
13
|
+
image_name = systemArgs[3],
|
14
|
+
selector = systemArgs[4],
|
15
|
+
globalBeforeCaptureJS = systemArgs[5],
|
16
|
+
pathBeforeCaptureJS = systemArgs[6];
|
17
|
+
|
18
|
+
globalBeforeCaptureJS = globalBeforeCaptureJS === 'false' ? false : globalBeforeCaptureJS;
|
19
|
+
pathBeforeCaptureJS = pathBeforeCaptureJS === 'false' ? false : pathBeforeCaptureJS;
|
20
|
+
|
21
|
+
var current_requests = 0;
|
22
|
+
var last_request_timeout;
|
23
|
+
var final_timeout;
|
24
|
+
|
25
|
+
page.viewportSize = { width: dimensions.viewportWidth, height: dimensions.viewportHeight};
|
26
|
+
page.settings = { loadImages: true, javascriptEnabled: javascriptEnabled };
|
27
|
+
|
28
|
+
// If you want to use additional phantomjs commands, place them here
|
29
|
+
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.17';
|
30
|
+
|
31
|
+
// You can place custom headers here, example below.
|
32
|
+
// page.customHeaders = {
|
33
|
+
|
34
|
+
// 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
|
35
|
+
|
36
|
+
// };
|
37
|
+
|
38
|
+
// If you want to set a cookie, just add your details below in the following way.
|
39
|
+
|
40
|
+
// phantom.addCookie({
|
41
|
+
// 'name': 'ckns_policy',
|
42
|
+
// 'value': '111',
|
43
|
+
// 'domain': '.bbc.co.uk'
|
44
|
+
// });
|
45
|
+
// phantom.addCookie({
|
46
|
+
// 'name': 'locserv',
|
47
|
+
// 'value': '1#l1#i=6691484:n=Oxford+Circus:h=e@w1#i=8:p=London@d1#1=l:2=e:3=e:4=2@n1#r=40',
|
48
|
+
// 'domain': '.bbc.co.uk'
|
49
|
+
// });
|
50
|
+
|
51
|
+
page.onResourceRequested = function(req) {
|
52
|
+
current_requests += 1;
|
53
|
+
};
|
54
|
+
|
55
|
+
page.onResourceReceived = function(res) {
|
56
|
+
if (res.stage === 'end') {
|
57
|
+
current_requests -= 1;
|
58
|
+
debounced_render();
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
page.open(url, function(status) {
|
63
|
+
if (status !== 'success') {
|
64
|
+
console.log('Error with page ' + url);
|
65
|
+
phantom.exit();
|
66
|
+
}
|
67
|
+
});
|
68
|
+
|
69
|
+
|
70
|
+
function debounced_render() {
|
71
|
+
clearTimeout(last_request_timeout);
|
72
|
+
clearTimeout(final_timeout);
|
73
|
+
|
74
|
+
// If there's no more ongoing resource requests, wait for 1 second before
|
75
|
+
// rendering, just in case the page kicks off another request
|
76
|
+
if (current_requests < 1) {
|
77
|
+
clearTimeout(final_timeout);
|
78
|
+
last_request_timeout = setTimeout(function() {
|
79
|
+
|
80
|
+
if (globalBeforeCaptureJS) {
|
81
|
+
require(globalBeforeCaptureJS)(page);
|
82
|
+
}
|
83
|
+
if (pathBeforeCaptureJS) {
|
84
|
+
require(pathBeforeCaptureJS)(page);
|
85
|
+
}
|
86
|
+
|
87
|
+
console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
|
88
|
+
page.clipRect = {
|
89
|
+
top: 0,
|
90
|
+
left: 0,
|
91
|
+
height: dimensions.viewportHeight,
|
92
|
+
width: dimensions.viewportWidth
|
93
|
+
};
|
94
|
+
page.render(image_name);
|
95
|
+
phantom.exit();
|
96
|
+
}, 1000);
|
97
|
+
}
|
98
|
+
|
99
|
+
// Sometimes, straggling requests never make it back, in which
|
100
|
+
// case, timeout after 5 seconds and render the page anyway
|
101
|
+
final_timeout = setTimeout(function() {
|
102
|
+
|
103
|
+
if (globalBeforeCaptureJS) {
|
104
|
+
require(globalBeforeCaptureJS)(page);
|
105
|
+
}
|
106
|
+
if (pathBeforeCaptureJS) {
|
107
|
+
require(pathBeforeCaptureJS)(page);
|
108
|
+
}
|
109
|
+
|
110
|
+
console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
|
111
|
+
page.clipRect = {
|
112
|
+
top: 0,
|
113
|
+
left: 0,
|
114
|
+
height: dimensions.viewportHeight,
|
115
|
+
width: dimensions.viewportWidth
|
116
|
+
};
|
117
|
+
page.render(image_name);
|
118
|
+
phantom.exit();
|
119
|
+
}, 5000);
|
120
|
+
}
|
121
|
+
|
122
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module.exports = function (browserEngine) {
|
2
|
+
browserEngine.evaluate(function(){
|
3
|
+
var a = document.querySelector('.ns-panel__hotspot--2');
|
4
|
+
var e = document.createEvent('MouseEvents');
|
5
|
+
e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
6
|
+
a.dispatchEvent(e);
|
7
|
+
waitforload = true;
|
8
|
+
});
|
9
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
// modules
|
2
|
+
var system = require('system'),
|
3
|
+
casper = require('casper').create();
|
4
|
+
|
5
|
+
// command line arguments
|
6
|
+
var url = casper.cli.get(0),
|
7
|
+
dimensions = requireRelative('_getDimensions.js')(casper.cli.get(1)),
|
8
|
+
image_name = casper.cli.get(2),
|
9
|
+
selector = casper.cli.get(3),
|
10
|
+
globalBeforeCaptureJS = casper.cli.get(4),
|
11
|
+
pathBeforeCaptureJS = casper.cli.get(5);
|
12
|
+
|
13
|
+
// functions
|
14
|
+
function requireRelative(file) {
|
15
|
+
// PhantomJS will automatically `require` relatively, but CasperJS needs some extra help. Hence this function.
|
16
|
+
// 'templates/javascript/casper.js' -> 'templates/javascript'
|
17
|
+
var currentFilePath = system.args[3].split('/');
|
18
|
+
currentFilePath.pop();
|
19
|
+
var fs = require('fs');
|
20
|
+
currentFilePath = fs.absolute(currentFilePath.join('/'));
|
21
|
+
return require(currentFilePath + '/' + file);
|
22
|
+
}
|
23
|
+
function snap() {
|
24
|
+
if (!selector) {
|
25
|
+
this.capture(image_name);
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
this.captureSelector(image_name, selector);
|
29
|
+
}
|
30
|
+
console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
|
31
|
+
}
|
32
|
+
|
33
|
+
// Casper can now do its magic
|
34
|
+
casper.start();
|
35
|
+
casper.open(url);
|
36
|
+
casper.viewport(dimensions.viewportWidth, dimensions.viewportHeight);
|
37
|
+
casper.then(function() {
|
38
|
+
if (globalBeforeCaptureJS) {
|
39
|
+
require('./' + globalBeforeCaptureJS)(this);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
casper.then(function() {
|
43
|
+
if (pathBeforeCaptureJS) {
|
44
|
+
require('./' + pathBeforeCaptureJS)(this);
|
45
|
+
}
|
46
|
+
});
|
47
|
+
// waits for all images to download before taking screenshots
|
48
|
+
// (broken images are a big cause of Wraith failures!)
|
49
|
+
// Credit: http://reff.it/8m3HYP
|
50
|
+
casper.waitFor(function() {
|
51
|
+
return this.evaluate(function() {
|
52
|
+
var images = document.getElementsByTagName('img');
|
53
|
+
return Array.prototype.every.call(images, function(i) { return i.complete; });
|
54
|
+
});
|
55
|
+
}, function then () {
|
56
|
+
snap.bind(this)();
|
57
|
+
});
|
58
|
+
|
59
|
+
casper.run();
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wraith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Blooman
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pry
|
@@ -188,15 +188,8 @@ files:
|
|
188
188
|
- README.md
|
189
189
|
- Rakefile
|
190
190
|
- assets/invalid.jpg
|
191
|
+
- assets/wraith-logo.png
|
191
192
|
- bin/wraith
|
192
|
-
- configs/component.yaml
|
193
|
-
- configs/config_nojs.yaml
|
194
|
-
- configs/custom_height.yaml
|
195
|
-
- configs/history.yaml
|
196
|
-
- configs/templates/component.yaml
|
197
|
-
- configs/templates/config.yaml
|
198
|
-
- configs/test_config--casper.yaml
|
199
|
-
- configs/test_config.yaml
|
200
193
|
- lib/wraith.rb
|
201
194
|
- lib/wraith/cli.rb
|
202
195
|
- lib/wraith/compare_images.rb
|
@@ -204,11 +197,6 @@ files:
|
|
204
197
|
- lib/wraith/folder.rb
|
205
198
|
- lib/wraith/gallery.rb
|
206
199
|
- lib/wraith/gallery_template/gallery_template.erb
|
207
|
-
- lib/wraith/javascript/beforeCapture.js
|
208
|
-
- lib/wraith/javascript/casper.js
|
209
|
-
- lib/wraith/javascript/customHeight.js
|
210
|
-
- lib/wraith/javascript/nojs.js
|
211
|
-
- lib/wraith/javascript/snap.js
|
212
200
|
- lib/wraith/save_images.rb
|
213
201
|
- lib/wraith/spider.rb
|
214
202
|
- lib/wraith/thumbnails.rb
|
@@ -216,11 +204,27 @@ files:
|
|
216
204
|
- lib/wraith/wraith.rb
|
217
205
|
- spec/base/global.png
|
218
206
|
- spec/base/path.png
|
207
|
+
- spec/configs/test_config--casper.yaml
|
208
|
+
- spec/configs/test_config--phantom.yaml
|
219
209
|
- spec/helpers.rb
|
220
210
|
- spec/js/global.js
|
221
211
|
- spec/js/path.js
|
212
|
+
- spec/thumbnails/test/test_image-1.png
|
213
|
+
- spec/thumbnails/test/test_image-2.png
|
214
|
+
- spec/thumbnails/test/test_image-diff.png
|
222
215
|
- spec/wraith_spec.rb
|
223
|
-
-
|
216
|
+
- templates/README.md
|
217
|
+
- templates/configs/component.yaml
|
218
|
+
- templates/configs/multiple_domains.yaml
|
219
|
+
- templates/configs/spider.yaml
|
220
|
+
- templates/javascript/README.md
|
221
|
+
- templates/javascript/_getDimensions.js
|
222
|
+
- templates/javascript/_phantom__common.js
|
223
|
+
- templates/javascript/beforeCapture--casper_example.js
|
224
|
+
- templates/javascript/beforeCapture--phantom_example.js
|
225
|
+
- templates/javascript/casper.js
|
226
|
+
- templates/javascript/phantom--nojs.js
|
227
|
+
- templates/javascript/phantom.js
|
224
228
|
- wraith.gemspec
|
225
229
|
homepage: https://github.com/BBC-News/wraith
|
226
230
|
licenses:
|
@@ -242,14 +246,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
246
|
version: '0'
|
243
247
|
requirements: []
|
244
248
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.
|
249
|
+
rubygems_version: 2.4.8
|
246
250
|
signing_key:
|
247
251
|
specification_version: 4
|
248
252
|
summary: Wraith is a screenshot comparison tool, created by developers at BBC News.
|
249
253
|
test_files:
|
250
254
|
- spec/base/global.png
|
251
255
|
- spec/base/path.png
|
256
|
+
- spec/configs/test_config--casper.yaml
|
257
|
+
- spec/configs/test_config--phantom.yaml
|
252
258
|
- spec/helpers.rb
|
253
259
|
- spec/js/global.js
|
254
260
|
- spec/js/path.js
|
261
|
+
- spec/thumbnails/test/test_image-1.png
|
262
|
+
- spec/thumbnails/test/test_image-2.png
|
263
|
+
- spec/thumbnails/test/test_image-diff.png
|
255
264
|
- spec/wraith_spec.rb
|
data/configs/component.yaml
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
#Headless browser option
|
2
|
-
browser:
|
3
|
-
phantomjs: "casperjs"
|
4
|
-
# slimerjs: "slimerjs"
|
5
|
-
|
6
|
-
#If you want to have multiple snapping files, set the file name here
|
7
|
-
snap_file: "lib/wraith/javascript/casper.js"
|
8
|
-
|
9
|
-
# Type the name of the directory that shots will be stored in
|
10
|
-
directory: 'shots'
|
11
|
-
|
12
|
-
# Add only 2 domains, key will act as a label
|
13
|
-
domains:
|
14
|
-
arabic: "http://www.bbc.com/arabic"
|
15
|
-
russian: "http://www.bbc.com/russian"
|
16
|
-
|
17
|
-
#Type screen widths below, here are a couple of examples
|
18
|
-
screen_widths:
|
19
|
-
- 320
|
20
|
-
- 600
|
21
|
-
- 768
|
22
|
-
- 1024
|
23
|
-
- 1280
|
24
|
-
|
25
|
-
#Type page URL paths below, here are a couple of examples
|
26
|
-
paths:
|
27
|
-
brand:
|
28
|
-
path: /
|
29
|
-
selector: '.site-brand'
|
30
|
-
|
31
|
-
#Amount of fuzz ImageMagick will use
|
32
|
-
fuzz: '20%'
|
33
|
-
|
34
|
-
#Set the filename of the spider file to use, if not specified it will fallback to spider.txt
|
35
|
-
# spider_file: bbc_co_uk_spider.txt
|
36
|
-
|
37
|
-
#Set the number of days to keep the site spider file
|
38
|
-
spider_days:
|
39
|
-
- 10
|
40
|
-
|
41
|
-
#Choose how results are displayed, by default alphanumeric. Different screen widths are always grouped.
|
42
|
-
#alphanumeric - all paths (with, and without, a difference) are shown, sorted by path
|
43
|
-
#diffs_first - all paths (with, and without, a difference) are shown, sorted by difference size (largest first)
|
44
|
-
#diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
|
45
|
-
mode: diffs_first
|
46
|
-
|
47
|
-
threshold: 15
|
data/configs/config_nojs.yaml
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
#Headless browser option
|
2
|
-
browser:
|
3
|
-
phantomjs: "phantomjs"
|
4
|
-
# slimerjs: "slimerjs"
|
5
|
-
|
6
|
-
#If you want to have multiple snapping files, set the file name here
|
7
|
-
snap_file: "lib/wraith/javascript/nojs.js"
|
8
|
-
|
9
|
-
# Type the name of the directory that shots will be stored in
|
10
|
-
directory: 'shots_nojs'
|
11
|
-
|
12
|
-
# Add only 2 domains, key will act as a label
|
13
|
-
domains:
|
14
|
-
arabic: "http://www.bbc.com/arabic"
|
15
|
-
russian: "http://www.bbc.com/russian"
|
16
|
-
|
17
|
-
#Type screen widths below, here are a couple of examples
|
18
|
-
screen_widths:
|
19
|
-
- 320
|
20
|
-
- 600
|
21
|
-
- 768
|
22
|
-
- 1024
|
23
|
-
- 1280
|
24
|
-
|
25
|
-
#Type page URL paths below, here are a couple of examples
|
26
|
-
paths:
|
27
|
-
home: /
|
28
|
-
uk_index: /uk
|
29
|
-
|
30
|
-
#Amount of fuzz ImageMagick will use
|
31
|
-
fuzz: '20%'
|
32
|
-
|
33
|
-
#Set the number of days to keep the site spider file
|
34
|
-
spider_days:
|
35
|
-
- 10
|
36
|
-
|
37
|
-
#A list of URLs to skip when spidering. Ruby regular expressions can be
|
38
|
-
#used, if prefixed with !ruby/regexp as defined in the YAML Cookbook
|
39
|
-
#http://www.yaml.org/YAML_for_ruby.html#regexps
|
40
|
-
#
|
41
|
-
# spider_skips:
|
42
|
-
# - /foo/bar.html # Matches /foo/bar.html explcitly
|
43
|
-
# - !ruby/regexp /^\/baz\// # Matches any URLs that start with /baz
|
data/configs/custom_height.yaml
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#Headless browser option
|
2
|
-
browser:
|
3
|
-
phantomjs: "phantomjs"
|
4
|
-
# slimerjs: "slimerjs"
|
5
|
-
|
6
|
-
#If you want to have multiple snapping files, set the file name here
|
7
|
-
snap_file: "lib/wraith/javascript/customHeight.js"
|
8
|
-
|
9
|
-
# Type the name of the directory that shots will be stored in
|
10
|
-
directory: 'shots'
|
11
|
-
|
12
|
-
# Add only 2 domains, key will act as a label
|
13
|
-
domains:
|
14
|
-
arabic: "http://www.bbc.com/arabic"
|
15
|
-
russian: "http://www.bbc.com/russian"
|
16
|
-
|
17
|
-
#Type screen widths below, here are a couple of examples
|
18
|
-
screen_widths:
|
19
|
-
# - widthxheight
|
20
|
-
- 480x320
|
21
|
-
- 400x600
|
22
|
-
- 600x768
|
23
|
-
- 800x1024
|
24
|
-
- 720x1280
|
25
|
-
|
26
|
-
#Type page URL paths below, here are a couple of examples
|
27
|
-
paths:
|
28
|
-
home: /
|
29
|
-
uk_index: /uk
|
30
|
-
|
31
|
-
#Amount of fuzz ImageMagick will use
|
32
|
-
fuzz: '20%'
|
33
|
-
|
34
|
-
#Set the number of days to keep the site spider file
|
35
|
-
spider_days:
|
36
|
-
- 10
|
37
|
-
|
38
|
-
#Choose how results are displayed, by default alphanumeric. Different screen widths are always grouped.
|
39
|
-
#alphanumeric - all paths (with, and without, a difference) are shown, sorted by path
|
40
|
-
#diffs_first - all paths (with, and without, a difference) are shown, sorted by difference size (largest first)
|
41
|
-
#diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
|
42
|
-
#mode: diffs_first
|