wraith 3.0.4 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/Gemfile +1 -1
  4. data/lib/wraith/cli.rb +108 -73
  5. data/lib/wraith/compare_images.rb +4 -2
  6. data/lib/wraith/crop.rb +3 -1
  7. data/lib/wraith/folder.rb +6 -4
  8. data/lib/wraith/gallery.rb +21 -22
  9. data/lib/wraith/helpers/capture_options.rb +52 -0
  10. data/lib/wraith/helpers/custom_exceptions.rb +8 -0
  11. data/lib/wraith/helpers/logger.rb +20 -0
  12. data/lib/wraith/helpers/save_metadata.rb +31 -0
  13. data/lib/wraith/{utilities.rb → helpers/utilities.rb} +5 -4
  14. data/lib/wraith/javascript/_helper.js +0 -2
  15. data/lib/wraith/javascript/casper.js +26 -16
  16. data/lib/wraith/javascript/phantom.js +148 -5
  17. data/lib/wraith/save_images.rb +28 -104
  18. data/lib/wraith/spider.rb +12 -5
  19. data/lib/wraith/thumbnails.rb +0 -2
  20. data/lib/wraith/validate.rb +98 -0
  21. data/lib/wraith/version.rb +1 -1
  22. data/lib/wraith/wraith.rb +19 -12
  23. data/spec/_helpers.rb +4 -10
  24. data/spec/before_capture_spec.rb +19 -10
  25. data/spec/config_spec.rb +2 -9
  26. data/spec/configs/test_config--casper.yaml +1 -5
  27. data/spec/construct_command_spec.rb +43 -0
  28. data/spec/gallery_spec.rb +1 -2
  29. data/spec/js/custom_snap_file.js +26 -16
  30. data/spec/js/global.js +2 -1
  31. data/spec/js/path.js +2 -1
  32. data/spec/resize_reload_spec.rb +4 -8
  33. data/spec/save_images_spec.rb +3 -2
  34. data/spec/validate_spec.rb +76 -0
  35. data/templates/configs/capture.yaml +61 -0
  36. data/templates/configs/history.yaml +81 -0
  37. data/templates/configs/spider.yaml +13 -2
  38. data/templates/javascript/cookies_and_headers--casper.js +16 -0
  39. data/templates/javascript/cookies_and_headers--phantom.js +26 -0
  40. data/templates/javascript/disable_javascript--casper.js +11 -0
  41. data/templates/javascript/disable_javascript--phantom.js +13 -0
  42. data/templates/javascript/interact--casper.js +11 -0
  43. data/templates/javascript/interact--phantom.js +17 -0
  44. data/templates/javascript/wait--casper.js +8 -0
  45. data/templates/javascript/wait--phantom.js +8 -0
  46. data/wraith.gemspec +1 -1
  47. metadata +27 -14
  48. data/lib/wraith/javascript/_phantom__common.js +0 -120
  49. data/lib/wraith/javascript/phantom--nojs.js +0 -6
  50. data/templates/configs/component.yaml +0 -60
  51. data/templates/configs/multiple_domains.yaml +0 -53
  52. data/templates/javascript/beforeCapture--casper_example.js +0 -12
  53. data/templates/javascript/beforeCapture--phantom_example.js +0 -36
@@ -0,0 +1,11 @@
1
+ // ######################################################
2
+ // This is an example module provided by Wraith.
3
+ // Feel free to amend for your own requirements.
4
+ // ######################################################
5
+ module.exports = function (casper, ready) {
6
+ // test interaction on the page
7
+ casper.wait(2000, function() {
8
+ casper.click('.ns-panel__hotspot--2');
9
+ ready();
10
+ });
11
+ }
@@ -0,0 +1,17 @@
1
+ // ######################################################
2
+ // This is an example module provided by Wraith.
3
+ // Feel free to amend for your own requirements.
4
+ // ######################################################
5
+ module.exports = function (phantom, ready) {
6
+
7
+ // test interaction on the page
8
+ phantom.evaluate(function(){
9
+ var a = document.querySelector('.ns-panel__hotspot--2');
10
+ var e = document.createEvent('MouseEvents');
11
+ e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
12
+ a.dispatchEvent(e);
13
+ waitforload = true;
14
+ });
15
+
16
+ ready();
17
+ }
@@ -0,0 +1,8 @@
1
+ // ######################################################
2
+ // This is an example module provided by Wraith.
3
+ // Feel free to amend for your own requirements.
4
+ // ######################################################
5
+ module.exports = function (casper, ready) {
6
+ // make Wraith wait a bit longer before taking the screenshot
7
+ casper.wait(2000, ready); // you MUST call the ready() callback for Wraith to continue
8
+ }
@@ -0,0 +1,8 @@
1
+ // ######################################################
2
+ // This is an example module provided by Wraith.
3
+ // Feel free to amend for your own requirements.
4
+ // ######################################################
5
+ module.exports = function (phantom, ready) {
6
+ // make Wraith wait a bit longer before taking the screenshot
7
+ setTimeout(ready, 2000); // you MUST call the ready() callback for Wraith to continue
8
+ }
data/wraith.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency 'image_size'
26
26
  spec.add_runtime_dependency 'anemone'
27
27
  spec.add_runtime_dependency 'robotex'
28
- spec.add_runtime_dependency 'nokogiri'
28
+ spec.add_runtime_dependency 'nokogiri', '1.6.7'
29
29
  spec.add_runtime_dependency 'log4r'
30
30
  spec.add_runtime_dependency 'thor'
31
31
  spec.add_runtime_dependency 'parallel'
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: 3.0.4
4
+ version: 3.1.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-12-03 00:00:00.000000000 Z
13
+ date: 2015-12-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry
@@ -100,16 +100,16 @@ dependencies:
100
100
  name: nokogiri
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - '>='
103
+ - - '='
104
104
  - !ruby/object:Gem::Version
105
- version: '0'
105
+ version: 1.6.7
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - '>='
110
+ - - '='
111
111
  - !ruby/object:Gem::Version
112
- version: '0'
112
+ version: 1.6.7
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: log4r
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -198,15 +198,18 @@ files:
198
198
  - lib/wraith/gallery.rb
199
199
  - lib/wraith/gallery_template/basic_template.erb
200
200
  - lib/wraith/gallery_template/slideshow_template.erb
201
+ - lib/wraith/helpers/capture_options.rb
202
+ - lib/wraith/helpers/custom_exceptions.rb
203
+ - lib/wraith/helpers/logger.rb
204
+ - lib/wraith/helpers/save_metadata.rb
205
+ - lib/wraith/helpers/utilities.rb
201
206
  - lib/wraith/javascript/_helper.js
202
- - lib/wraith/javascript/_phantom__common.js
203
207
  - lib/wraith/javascript/casper.js
204
- - lib/wraith/javascript/phantom--nojs.js
205
208
  - lib/wraith/javascript/phantom.js
206
209
  - lib/wraith/save_images.rb
207
210
  - lib/wraith/spider.rb
208
211
  - lib/wraith/thumbnails.rb
209
- - lib/wraith/utilities.rb
212
+ - lib/wraith/validate.rb
210
213
  - lib/wraith/version.rb
211
214
  - lib/wraith/wraith.rb
212
215
  - spec/_helpers.rb
@@ -216,6 +219,7 @@ files:
216
219
  - spec/config_spec.rb
217
220
  - spec/configs/test_config--casper.yaml
218
221
  - spec/configs/test_config--phantom.yaml
222
+ - spec/construct_command_spec.rb
219
223
  - spec/gallery_spec.rb
220
224
  - spec/js/custom_snap_file.js
221
225
  - spec/js/global.js
@@ -225,12 +229,19 @@ files:
225
229
  - spec/thumbnails/home/test_image-afrique.png
226
230
  - spec/thumbnails/home/test_image-diff.png
227
231
  - spec/thumbnails/home/test_image-russian.png
232
+ - spec/validate_spec.rb
228
233
  - templates/README.md
229
- - templates/configs/component.yaml
230
- - templates/configs/multiple_domains.yaml
234
+ - templates/configs/capture.yaml
235
+ - templates/configs/history.yaml
231
236
  - templates/configs/spider.yaml
232
- - templates/javascript/beforeCapture--casper_example.js
233
- - templates/javascript/beforeCapture--phantom_example.js
237
+ - templates/javascript/cookies_and_headers--casper.js
238
+ - templates/javascript/cookies_and_headers--phantom.js
239
+ - templates/javascript/disable_javascript--casper.js
240
+ - templates/javascript/disable_javascript--phantom.js
241
+ - templates/javascript/interact--casper.js
242
+ - templates/javascript/interact--phantom.js
243
+ - templates/javascript/wait--casper.js
244
+ - templates/javascript/wait--phantom.js
234
245
  - wraith.gemspec
235
246
  homepage: https://github.com/BBC-News/wraith
236
247
  licenses:
@@ -252,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
263
  version: '0'
253
264
  requirements: []
254
265
  rubyforge_project:
255
- rubygems_version: 2.4.8
266
+ rubygems_version: 2.4.7
256
267
  signing_key:
257
268
  specification_version: 4
258
269
  summary: Wraith is a screenshot comparison tool, created by developers at BBC News.
@@ -264,6 +275,7 @@ test_files:
264
275
  - spec/config_spec.rb
265
276
  - spec/configs/test_config--casper.yaml
266
277
  - spec/configs/test_config--phantom.yaml
278
+ - spec/construct_command_spec.rb
267
279
  - spec/gallery_spec.rb
268
280
  - spec/js/custom_snap_file.js
269
281
  - spec/js/global.js
@@ -273,3 +285,4 @@ test_files:
273
285
  - spec/thumbnails/home/test_image-afrique.png
274
286
  - spec/thumbnails/home/test_image-diff.png
275
287
  - spec/thumbnails/home/test_image-russian.png
288
+ - spec/validate_spec.rb
@@ -1,120 +0,0 @@
1
- module.exports = function (config) {
2
-
3
- // config
4
- var systemArgs = config.systemArgs,
5
- javascriptEnabled = config.javascriptEnabled;
6
-
7
- // modules
8
- var page = require('webpage').create(),
9
- helper = require('./_helper.js')(systemArgs[2]);
10
-
11
- // command line arguments
12
- var url = systemArgs[1],
13
- dimensions = helper.dimensions,
14
- image_name = systemArgs[3],
15
- selector = systemArgs[4],
16
- globalBeforeCaptureJS = systemArgs[5],
17
- pathBeforeCaptureJS = systemArgs[6],
18
- dimensionsProcessed = 0,
19
- currentDimensions;
20
-
21
- globalBeforeCaptureJS = globalBeforeCaptureJS === 'false' ? false : globalBeforeCaptureJS;
22
- pathBeforeCaptureJS = pathBeforeCaptureJS === 'false' ? false : pathBeforeCaptureJS;
23
-
24
- var current_requests = 0;
25
- var last_request_timeout;
26
- var final_timeout;
27
-
28
- if (helper.takingMultipleScreenshots(dimensions)) {
29
- currentDimensions = dimensions[0];
30
- image_name = helper.replaceImageNameWithDimensions(image_name, currentDimensions);
31
- }
32
- else {
33
- currentDimensions = dimensions;
34
- }
35
-
36
- page.settings = { loadImages: true, javascriptEnabled: javascriptEnabled };
37
-
38
- // If you want to use additional phantomjs commands, place them here
39
- 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';
40
-
41
- page.onResourceRequested = function(req) {
42
- current_requests += 1;
43
- };
44
-
45
- page.onResourceReceived = function(res) {
46
- if (res.stage === 'end') {
47
- current_requests -= 1;
48
- debounced_render();
49
- }
50
- };
51
-
52
- page.open(url, function(status) {
53
- if (status !== 'success') {
54
- console.log('Error with page ' + url);
55
- phantom.exit();
56
- }
57
- });
58
-
59
- function runSetupJavaScriptThenCaptureImage() {
60
- resize();
61
- if (globalBeforeCaptureJS) {
62
- require(globalBeforeCaptureJS)(page);
63
- }
64
- if (pathBeforeCaptureJS) {
65
- require(pathBeforeCaptureJS)(page);
66
- }
67
- resizeAndCaptureImage();
68
- }
69
-
70
- function resize() {
71
- page.viewportSize = { width: currentDimensions.viewportWidth, height: currentDimensions.viewportHeight};
72
- }
73
-
74
- function resizeAndCaptureImage() {
75
- console.log('Snapping ' + url + ' at: ' + currentDimensions.viewportWidth + 'x' + currentDimensions.viewportHeight);
76
- resize();
77
- setTimeout(captureImage, 1000); // give page time to re-render properly
78
- }
79
-
80
- function captureImage() {
81
- page.clipRect = {
82
- top: 0,
83
- left: 0,
84
- height: currentDimensions.viewportHeight,
85
- width: currentDimensions.viewportWidth
86
- };
87
- page.render(image_name);
88
-
89
- dimensionsProcessed++;
90
- if (helper.takingMultipleScreenshots(dimensions) && dimensionsProcessed < dimensions.length) {
91
- currentDimensions = dimensions[dimensionsProcessed];
92
- image_name = helper.replaceImageNameWithDimensions(image_name, currentDimensions);
93
- setTimeout(resizeAndCaptureImage, 1000);
94
- }
95
- else {
96
- // prevent CI from failing from 'Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL' errors
97
- // see https://github.com/n1k0/casperjs/issues/1068
98
- setTimeout(function(){
99
- phantom.exit();
100
- }, 30);
101
- }
102
- }
103
-
104
- function debounced_render() {
105
- clearTimeout(last_request_timeout);
106
- clearTimeout(final_timeout);
107
-
108
- // If there's no more ongoing resource requests, wait for 1 second before
109
- // rendering, just in case the page kicks off another request
110
- if (current_requests < 1) {
111
- clearTimeout(final_timeout);
112
- last_request_timeout = setTimeout(runSetupJavaScriptThenCaptureImage, 1000);
113
- }
114
-
115
- // Sometimes, straggling requests never make it back, in which
116
- // case, timeout after 5 seconds and render the page anyway
117
- final_timeout = setTimeout(runSetupJavaScriptThenCaptureImage, 5000);
118
- }
119
-
120
- }
@@ -1,6 +0,0 @@
1
- var system = require('system');
2
-
3
- require('./_phantom__common.js')({
4
- systemArgs: system.args,
5
- javascriptEnabled: false
6
- });
@@ -1,60 +0,0 @@
1
- # Add as many domains as necessary. Key will act as a label
2
- domains:
3
- english: "http://www.bbc.co.uk"
4
-
5
- # (optional) JavaScript file to execute before taking screenshot of every path.
6
- # Can be used to reload current page with headers specified, or to dynamically
7
- # AJAX in content, or all manner of other uses!
8
- #before_capture: 'javascript/global.js'
9
-
10
- # Type page URL paths below, here are a couple of examples
11
- paths:
12
- clickable_guide:
13
- path: /news/entertainment-arts-27221191
14
- selector: '.idt__news' # selector to take a screenshot of
15
- clickable_guide__after_click:
16
- path: /news/entertainment-arts-27221191
17
- selector: '.idt__news'
18
- # (optional) JavaScript file to execute before taking the screenshot of this path.
19
- # This is always executed AFTER the 'global' before_capture hook toward the top of this file.
20
- before_capture: 'javascript/beforeCapture--casper_example.js'
21
-
22
- # amount of fuzz ImageMagick will use when comparing images. A higher fuzz makes the comparison less strict.
23
- fuzz: '20%'
24
-
25
- # the maximum acceptable level of difference (in %) between two images.
26
- # Wraith considers it a failure if an image diff goes above this threshold.
27
- threshold: 5
28
-
29
- # screen widths (and optional height) to resize the browser to before taking the screenshot
30
- screen_widths:
31
- - 320
32
- - 600x768
33
- - 768
34
- - 1024
35
- - 1280
36
-
37
- # resize to each screen width, or reload at each screen width. (The former is more efficient).
38
- resize_or_reload: 'resize'
39
-
40
- # the engine to run Wraith with.
41
- browser: "casperjs"
42
-
43
- # the directory that your base screenshots will be stored in
44
- history_dir: 'shots_base'
45
-
46
- # the directory that your latest screenshots will be stored in
47
- directory: 'shots'
48
-
49
- gallery:
50
- template: 'slideshow_template' # 'basic_template' (default)
51
- thumb_width: 200
52
- thumb_height: 200
53
-
54
- # choose how results are displayed in the gallery (default is `alphanumeric` if omitted)
55
- # Different screen widths are always grouped together.
56
- # Options:
57
- # alphanumeric - all paths (with or without a difference) are shown, sorted by path
58
- # diffs_first - all paths (with or without a difference) are shown, sorted by difference size (largest first)
59
- # diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
60
- mode: alphanumeric
@@ -1,53 +0,0 @@
1
- # Add as many domains as necessary. Key will act as a label
2
- domains:
3
- arabic: "http://www.bbc.com/arabic"
4
- persian: "http://www.bbc.com/persian"
5
- russian: "http://www.bbc.com/russian"
6
-
7
- # (optional) JavaScript file to execute before taking screenshot of every path.
8
- # Can be used to reload current page with headers specified, or to dynamically
9
- # AJAX in content, or all manner of other uses!
10
- #before_capture: 'javascript/global.js'
11
-
12
- # Type page URL paths below, here are a couple of examples.
13
- # They should exist for all of the domains you've specified above.
14
- paths:
15
- home: /
16
- interactivity: /interactivity
17
-
18
- # amount of fuzz ImageMagick will use when comparing images. A higher fuzz makes the comparison less strict.
19
- fuzz: '20%'
20
-
21
- # the maximum acceptable level of difference (in %) between two images.
22
- # Wraith considers it a failure if an image diff goes above this threshold.
23
- threshold: 5
24
-
25
- # screen widths (and optional height) to resize the browser to before taking the screenshot
26
- screen_widths:
27
- - 320
28
- - 600x768
29
- - 768
30
- - 1024
31
- - 1280
32
-
33
- # the engine to run Wraith with. Examples: 'phantomjs', 'casperjs', 'slimerjs'
34
- browser: "phantomjs"
35
-
36
- # the directory that your base screenshots will be stored in
37
- history_dir: 'shots_base'
38
-
39
- # the directory that your latest screenshots will be stored in
40
- directory: 'shots'
41
-
42
- gallery:
43
- template: 'slideshow_template' # 'basic_template' (default)
44
- thumb_width: 200
45
- thumb_height: 200
46
-
47
- # choose how results are displayed in the gallery (default is `alphanumeric` if omitted)
48
- # Different screen widths are always grouped together.
49
- # Options:
50
- # alphanumeric - all paths (with or without a difference) are shown, sorted by path
51
- # diffs_first - all paths (with or without a difference) are shown, sorted by difference size (largest first)
52
- # diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
53
- mode: diffs_first
@@ -1,12 +0,0 @@
1
- module.exports = function (casper) {
2
-
3
- /* you may want to test some interaction on the page */
4
- casper.wait(2000, function() {
5
- casper.click('.ns-panel__hotspot--2');
6
- });
7
-
8
- /* or you may want to see how your page looks without JavaScript */
9
- // casper.options.pageSettings.javascriptEnabled = false;
10
- // casper.thenOpen(casper.page.url);
11
-
12
- }
@@ -1,36 +0,0 @@
1
- module.exports = function (phantom) {
2
-
3
- /* you may want to test some interaction on the page */
4
- phantom.evaluate(function(){
5
- var a = document.querySelector('.ns-panel__hotspot--2');
6
- var e = document.createEvent('MouseEvents');
7
- e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
8
- a.dispatchEvent(e);
9
- waitforload = true;
10
- });
11
-
12
- /* or you may want to see how your page looks without JavaScript */
13
- // phantom.settings.javascriptEnabled = false;
14
- // phantom.open(phantom.page.url);
15
-
16
- // You can place custom headers here, example below.
17
- // page.customHeaders = {
18
-
19
- // 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
20
-
21
- // };
22
-
23
- // If you want to set a cookie, just add your details below in the following way.
24
-
25
- // phantom.addCookie({
26
- // 'name': 'ckns_policy',
27
- // 'value': '111',
28
- // 'domain': '.bbc.co.uk'
29
- // });
30
- // phantom.addCookie({
31
- // 'name': 'locserv',
32
- // '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',
33
- // 'domain': '.bbc.co.uk'
34
- // });
35
-
36
- }