wraith 2.5.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afbb6584d3a5e210ab14042805e24ba4e5d5fdd3
4
- data.tar.gz: d61a1f542d94c1b5e61be170b682bd3102e5824f
3
+ metadata.gz: cc02a9bdf3aceb57ec1790b0670454646ac9adbf
4
+ data.tar.gz: 4d9267de7cb2689b6bb01129fc4f25dbfd76c89e
5
5
  SHA512:
6
- metadata.gz: 094cb5cf2dcd038666eb604adde015a6426a45a2474b6b8eeef2618903ed2ca95cb3e5a538bd9c1324c658cac03b8806ab7ef2d5775d97bbc0781961c96a86cd
7
- data.tar.gz: 247daece8faca88bcfca99be0d7968a9bba5609e2f839e30d1208c4120fec57a18932ed51940f7a99f9d9f9755e42fef25107c9d4f18f1b52d074bab63a6c79c
6
+ metadata.gz: 883098ff0a08426b8532e29491580ad14ef854777acea133a3da71f25b442e92b65688718bea5e18c5d2db5caa6e4151706c1b29d3cf41eee4c55be0ed905cc1
7
+ data.tar.gz: 4899954af25ca0b3645dada0519c09c22a97547a6283fe674f67cf580438bf726f248c225b7cc0b5b8013336b4e6070ffc50f2cba8df5177a5b501dd3ccc61e4
@@ -7,6 +7,7 @@ notifications:
7
7
  email:
8
8
  recipients:
9
9
  - david.blooman@bbc.co.uk
10
+ - chris.ashton@bbc.co.uk
10
11
  on_failure: change
11
12
  on_success: never
12
13
  slack:
data/README.md CHANGED
@@ -1,15 +1,18 @@
1
- # Wraith
2
-
3
- [![Build Status](https://secure.travis-ci.org/BBC-News/wraith.png?branch=master)](http://travis-ci.org/BBC-News/wraith)
4
- [![Gem Version](https://badge.fury.io/rb/wraith.svg)](http://badge.fury.io/rb/wraith)
5
- [![Code Climate](https://codeclimate.com/github/BBC-News/wraith.png)](https://codeclimate.com/github/BBC-News/wraith)
6
- [![Join the chat at https://gitter.im/BBC-News/wraith](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/BBC-News/wraith?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
-
8
- * Website: http://responsivenews.co.uk
9
- * Source: http://github.com/bbc-news/wraith
10
-
11
- Wraith is a screenshot comparison tool, created by developers at BBC News.
12
-
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/BBC-News/wraith/master/wraith-logo.png">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="http://travis-ci.org/BBC-News/wraith" target="_blank"><img src="https://secure.travis-ci.org/BBC-News/wraith.png?branch=master"></a>
7
+ <a href="https://rubygems.org/gems/wraith" target="_blank"><img src="https://img.shields.io/gem/v/wraith.svg"></a>
8
+ <a href="https://codeclimate.com/github/BBC-News/wraith" target="_blank"><img src="https://codeclimate.com/github/BBC-News/wraith.png"></a>
9
+ </p>
10
+
11
+ <p align="center">
12
+ Wraith is a screenshot comparison tool, created by developers at BBC News.
13
+ <br>
14
+ <a href="http://responsivenews.co.uk" target="_blank">Website</a> • <a href="http://github.com/bbc-news/wraith" target="_blank">Source</a>
15
+ </p>
13
16
 
14
17
  ## What is it?
15
18
 
@@ -31,7 +34,7 @@ diff](http://bbc-news.github.io/wraith/img/wraith.png)
31
34
  Imagemagick and PhantomJS are required to use Wraith, install via your favourite package manager. You can also use SlimerJS and CasperJS, CasperJS can be used to target specific selectors. To read our detailed instructions for setup and install, as well as example configs, visit [wraith docs](http://bbc-news.github.io/wraith/index.html)
32
35
 
33
36
  ```sh
34
- brew install phantomjs
37
+ brew install phantomjs
35
38
  brew install imagemagick
36
39
  ```
37
40
 
@@ -60,7 +63,7 @@ wraith setup
60
63
 
61
64
  ### CLI
62
65
 
63
- There are other commands also available, these all expect a config_name to be passed as an option. Wraith will look for the config file at `configs/[config_name].yaml`.
66
+ There are other commands also available, these all expect a config_name to be passed as an option. Wraith will look for the config file at `configs/[config_name].yaml`.
64
67
 
65
68
  ```sh
66
69
  wraith capture [config_name] # A full Wraith job
@@ -8,11 +8,11 @@ snap_file: "javascript/casper.js"
8
8
 
9
9
  # Type the name of the directory that shots will be stored in
10
10
  directory: 'shots'
11
+ history_dir: 'shots_base'
11
12
 
12
- # Add only 2 domains, key will act as a label
13
+ # Add as many domains as necessary. Key will act as a label
13
14
  domains:
14
- russian: "http://www.bbc.com/russian"
15
- arabic: "http://www.bbc.com/arabic"
15
+ english: "http://www.bbc.co.uk/news"
16
16
 
17
17
  #Type screen widths below, here are a couple of examples
18
18
  screen_widths:
@@ -24,9 +24,13 @@ screen_widths:
24
24
 
25
25
  #Type page URL paths below, here are a couple of examples
26
26
  paths:
27
- brand:
28
- path: /
29
- selector: '.site-brand'
27
+ clickable_guide:
28
+ path: /entertainment-arts-27221191
29
+ selector: '.idt__news'
30
+ clickable_guide__after_click:
31
+ path: /entertainment-arts-27221191
32
+ selector: '.idt__news'
33
+ before_capture: 'javascript/beforeCapture.js'
30
34
 
31
35
  #Amount of fuzz ImageMagick will use
32
36
  fuzz: '20%'
@@ -11,7 +11,7 @@ directory: 'shots'
11
11
 
12
12
  # Add only 2 domains, key will act as a label
13
13
  domains:
14
- english: "http://www.live.bbc.co.uk/news"
14
+ arabic: "http://www.live.bbc.co.uk/arabic"
15
15
  russian: "http://www.live.bbc.co.uk/russian"
16
16
 
17
17
  #Type screen widths below, here are a couple of examples
@@ -25,7 +25,7 @@ screen_widths:
25
25
  #Type page URL paths below, here are a couple of examples
26
26
  paths:
27
27
  home: /
28
- uk_index: /uk
28
+ uk_index: /topics/video
29
29
 
30
30
  #Amount of fuzz ImageMagick will use
31
31
  fuzz: '20%'
@@ -0,0 +1,29 @@
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
+ afrique: "http://www.bbc.com/afrique"
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
+ - 1280
22
+
23
+ #Type page URL paths below, here are a couple of examples
24
+ paths:
25
+ home: /
26
+ uk_index: /uk
27
+
28
+ #Amount of fuzz ImageMagick will use
29
+ fuzz: '20%'
@@ -14,19 +14,20 @@ class Wraith::CLI < Thor
14
14
  attr_accessor :config_name
15
15
 
16
16
  def self.source_root
17
- File.expand_path("../../../templates/", __FILE__)
17
+ File.expand_path("../../../", __FILE__)
18
18
  end
19
19
 
20
20
  desc "setup", "creates config folder and default config"
21
21
  def setup
22
- template("configs/config.yaml", "configs/config.yaml")
23
- template("javascript/snap.js", "javascript/snap.js")
22
+ template("configs/templates/config.yaml", "configs/config.yaml")
23
+ template("lib/wraith/javascript/snap.js", "javascript/snap.js")
24
24
  end
25
25
 
26
26
  desc "setup_casper", "creates config folder and default config for casper"
27
27
  def setup_casper
28
- template("configs/component.yaml", "configs/component.yaml")
29
- template("javascript/casper.js", "javascript/casper.js")
28
+ template("configs/templates/component.yaml", "configs/component.yaml")
29
+ template("lib/wraith/javascript/casper.js", "javascript/casper.js")
30
+ template("lib/wraith/javascript/beforeCapture.js", "javascript/beforeCapture.js")
30
31
  end
31
32
 
32
33
  desc "reset_shots [config_name]", "removes all the files in the shots folder"
@@ -0,0 +1,5 @@
1
+ module.exports = function (casper) {
2
+ casper.wait(2000, function() {
3
+ casper.click('.ns-panel__hotspot--2');
4
+ });
5
+ }
@@ -7,14 +7,42 @@ var url = casper.cli.get(0);
7
7
  var view_port_width = casper.cli.get(1);
8
8
  var image_name = casper.cli.get(2);
9
9
  var selector = casper.cli.get(3);
10
+ var globalBeforeCaptureJS = casper.cli.get(4);
11
+ var pathBeforeCaptureJS = casper.cli.get(5);
10
12
 
11
- casper.start(url, function() {
12
- this.viewport(view_port_width, 1500).then(function(){
13
- this.wait(2000, function() {
14
- this.captureSelector(image_name, selector);
15
- console.log('Snapping ' + url + ' at width ' + view_port_width);
16
- });
13
+ function snap() {
14
+ if (selector == undefined) {
15
+ this.capture(image_name);
16
+ }
17
+ else {
18
+ this.captureSelector(image_name, selector);
19
+ }
20
+ console.log('Snapping ' + url + ' at width ' + view_port_width);
21
+ }
22
+
23
+ casper.start();
24
+ casper.open(url);
25
+ casper.viewport(view_port_width, 1500);
26
+ casper.then(function() {
27
+ if (globalBeforeCaptureJS) {
28
+ require('./' + globalBeforeCaptureJS)(this);
29
+ }
30
+ });
31
+ casper.then(function() {
32
+ if (pathBeforeCaptureJS) {
33
+ require('./' + pathBeforeCaptureJS)(this);
34
+ }
35
+ });
36
+ // waits for all images to download before taking screenshots
37
+ // (broken images are a big cause of Wraith failures!)
38
+ // Credit: http://reff.it/8m3HYP
39
+ casper.waitFor(function() {
40
+ return this.evaluate(function() {
41
+ var images = document.getElementsByTagName('img');
42
+ return Array.prototype.every.call(images, function(i) { return i.complete; });
17
43
  });
44
+ }, function then () {
45
+ snap.bind(this)();
18
46
  });
19
47
 
20
48
  casper.run();
@@ -29,23 +29,23 @@ class Wraith::SaveImages
29
29
  base_file_name = meta.file_names(width, label, meta.base_label)
30
30
  compare_file_name = meta.file_names(width, label, meta.compare_label)
31
31
 
32
- jobs << [label, settings.path, width, settings.base_url, base_file_name, settings.selector]
33
- jobs << [label, settings.path, width, settings.compare_url, compare_file_name, settings.selector] unless settings.compare_url.nil?
32
+ jobs << [label, settings.path, width, settings.base_url, base_file_name, settings.selector, wraith.before_capture, settings.before_capture]
33
+ jobs << [label, settings.path, width, settings.compare_url, compare_file_name, settings.selector, wraith.before_capture, settings.before_capture] unless settings.compare_url.nil?
34
34
  end
35
35
  end
36
36
  parallel_task(jobs)
37
37
  end
38
38
 
39
- def capture_page_image(browser, url, width, file_name, selector)
40
- puts `"#{browser}" #{wraith.phantomjs_options} "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}" "#{selector}"`
39
+ def capture_page_image(browser, url, width, file_name, selector, global_before_capture, path_before_capture)
40
+ puts `"#{browser}" #{wraith.phantomjs_options} "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}" "#{selector}" "#{global_before_capture}" "#{path_before_capture}"`
41
41
  end
42
42
 
43
43
  private
44
44
 
45
45
  def parallel_task(jobs)
46
- Parallel.each(jobs, :in_threads => 8) do |_label, _path, width, url, filename, selector|
46
+ Parallel.each(jobs, :in_threads => 8) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture|
47
47
  begin
48
- attempt_image_capture(width, url, filename, selector, 5)
48
+ attempt_image_capture(width, url, filename, selector, global_before_capture, path_before_capture, 5)
49
49
  rescue => e
50
50
  puts e
51
51
  create_invalid_image(filename, width)
@@ -53,9 +53,9 @@ class Wraith::SaveImages
53
53
  end
54
54
  end
55
55
 
56
- def attempt_image_capture(width, url, filename, selector, max_attempts)
56
+ def attempt_image_capture(width, url, filename, selector, global_before_capture, path_before_capture, max_attempts)
57
57
  max_attempts.times do |i|
58
- capture_page_image meta.engine, url, width, filename, selector
58
+ capture_page_image meta.engine, url, width, filename, selector, global_before_capture, path_before_capture
59
59
 
60
60
  return if File.exist? filename
61
61
 
@@ -91,7 +91,11 @@ class CaptureOptions
91
91
  end
92
92
 
93
93
  def selector
94
- casper_selector(options)
94
+ options["selector"] || " "
95
+ end
96
+
97
+ def before_capture
98
+ options["before_capture"] || "false"
95
99
  end
96
100
 
97
101
  def base_url
@@ -113,10 +117,6 @@ class CaptureOptions
113
117
  def has_casper(options)
114
118
  options["path"] ? options["path"] : options
115
119
  end
116
-
117
- def casper_selector(options)
118
- options["selector"] ? options["selector"] : " "
119
- end
120
120
  end
121
121
 
122
122
  class SaveMetadata
@@ -1,3 +1,3 @@
1
1
  module Wraith
2
- VERSION = "2.5.2"
2
+ VERSION = "2.6.0"
3
3
  end
@@ -27,6 +27,10 @@ class Wraith::Wraith
27
27
  @config["snap_file"] ? @config["snap_file"] : File.expand_path("lib/wraith/javascript/snap.js")
28
28
  end
29
29
 
30
+ def before_capture
31
+ @config["before_capture"] || "false"
32
+ end
33
+
30
34
  def widths
31
35
  @config["screen_widths"]
32
36
  end
Binary file
Binary file
@@ -0,0 +1,22 @@
1
+ def create_diff_image
2
+ wraith.engine.each do |_type, engine|
3
+ saving.capture_page_image(engine, test_url1, 320, test_image1, selector, 'false', 'false')
4
+ saving.capture_page_image(engine, test_url2, 320, test_image2, selector, 'false', 'false')
5
+ end
6
+ end
7
+
8
+ def crop_images
9
+ Wraith::CropImages.new(config_name).crop_images
10
+ end
11
+
12
+ def compare_images
13
+ Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
14
+ end
15
+
16
+ def run_js_then_capture(config)
17
+ generated_image = 'shots/test/temporary_jsified_image.png'
18
+ saving.capture_page_image('casperjs', test_url1, 320, generated_image, selector, config[:global_js], config[:path_js])
19
+ Wraith::CompareImages.new(config_name).compare_task(generated_image, config[:output_should_look_like], diff_image, data_txt)
20
+ diff = File.open('shots/test/test.txt', "rb").read
21
+ expect(diff).to eq '0.0'
22
+ end
@@ -0,0 +1,6 @@
1
+ module.exports = function (casper) {
2
+ casper.evaluate(function () {
3
+ document.body.innerHTML = '&nbsp;';
4
+ document.body.style['background-color'] = 'red';
5
+ });
6
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = function (casper) {
2
+ casper.evaluate(function () {
3
+ document.body.innerHTML = '&nbsp;';
4
+ document.body.style['background-color'] = 'green';
5
+ });
6
+ }
@@ -1,5 +1,6 @@
1
1
  require "rspec"
2
2
  require "image_size"
3
+ require "helpers"
3
4
  require "./lib/wraith/cli"
4
5
 
5
6
  describe Wraith do
@@ -68,7 +69,7 @@ describe Wraith do
68
69
 
69
70
  it "saves image" do
70
71
  wraith.engine.each do |_type, engine|
71
- saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
72
+ saving.capture_page_image(engine, test_url1, 320, test_image1, selector, 'false', 'false')
72
73
  end
73
74
 
74
75
  expect(image_size[0]).to eq 320
@@ -87,7 +88,7 @@ describe Wraith do
87
88
  end
88
89
  end
89
90
 
90
- describe "When generating tumbnails" do
91
+ describe "When generating thumbnails" do
91
92
  it "produce thumbnails" do
92
93
  create_diff_image
93
94
  crop_images
@@ -99,19 +100,38 @@ describe Wraith do
99
100
  expect(File).to exist("shots/thumbnails/test/test_diff.png")
100
101
  end
101
102
  end
102
- end
103
103
 
104
- def create_diff_image
105
- wraith.engine.each do |_type, engine|
106
- saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
107
- saving.capture_page_image(engine, test_url2, 320, test_image2, selector)
108
- end
109
- end
104
+ describe "When hooking into beforeCapture" do
105
+ let(:config_name) { "test_config--casper" }
106
+ let(:saving) { Wraith::SaveImages.new(config_name) }
107
+ let(:wraith) { Wraith::Wraith.new(config_name) }
108
+ let(:selector) { "body" }
109
+ let(:before_suite_js) { "spec/js/global.js" }
110
+ let(:before_capture_js) { "spec/js/path.js" }
111
+
112
+ it "Executes the global JS before capturing" do
113
+ run_js_then_capture(
114
+ global_js: before_suite_js,
115
+ path_js: 'false',
116
+ output_should_look_like: 'spec/base/global.png'
117
+ )
118
+ end
110
119
 
111
- def crop_images
112
- Wraith::CropImages.new(config_name).crop_images
113
- end
120
+ it "Executes the path-level JS before capturing" do
121
+ run_js_then_capture(
122
+ global_js: 'false',
123
+ path_js: before_capture_js,
124
+ output_should_look_like: 'spec/base/path.png'
125
+ )
126
+ end
127
+
128
+ it "Executes the global JS before the path-level JS" do
129
+ run_js_then_capture(
130
+ global_js: before_suite_js,
131
+ path_js: before_capture_js,
132
+ output_should_look_like: 'spec/base/path.png'
133
+ )
134
+ end
135
+ end
114
136
 
115
- def compare_images
116
- Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
117
137
  end
Binary file
@@ -6,8 +6,8 @@ require 'wraith/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'wraith'
8
8
  spec.version = Wraith::VERSION
9
- spec.authors = ['Dave Blooman', 'Simon Thulbourn']
10
- spec.email = ['david.blooman@gmail.com', 'simon+github@thulbourn.com']
9
+ spec.authors = ['Dave Blooman', 'Simon Thulbourn', 'Chris Ashton']
10
+ spec.email = ['david.blooman@gmail.com', 'simon+github@thulbourn.com', 'chrisashtonweb@gmail.com']
11
11
  spec.summary = 'Wraith is a screenshot comparison tool, created by developers at BBC News.'
12
12
  spec.description = 'Wraith is a screenshot comparison tool, created by developers at BBC News.'
13
13
  spec.homepage = 'https://github.com/BBC-News/wraith'
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wraith
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Blooman
8
8
  - Simon Thulbourn
9
+ - Chris Ashton
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-06-15 00:00:00.000000000 Z
13
+ date: 2015-08-20 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: pry
@@ -170,6 +171,7 @@ description: Wraith is a screenshot comparison tool, created by developers at BB
170
171
  email:
171
172
  - david.blooman@gmail.com
172
173
  - simon+github@thulbourn.com
174
+ - chrisashtonweb@gmail.com
173
175
  executables:
174
176
  - wraith
175
177
  extensions: []
@@ -188,10 +190,12 @@ files:
188
190
  - assets/invalid.jpg
189
191
  - bin/wraith
190
192
  - configs/component.yaml
191
- - configs/config.yaml
192
193
  - configs/config_nojs.yaml
193
194
  - configs/custom_height.yaml
194
195
  - configs/history.yaml
196
+ - configs/templates/component.yaml
197
+ - configs/templates/config.yaml
198
+ - configs/test_config--casper.yaml
195
199
  - configs/test_config.yaml
196
200
  - lib/wraith.rb
197
201
  - lib/wraith/cli.rb
@@ -200,6 +204,7 @@ files:
200
204
  - lib/wraith/folder.rb
201
205
  - lib/wraith/gallery.rb
202
206
  - lib/wraith/gallery_template/gallery_template.erb
207
+ - lib/wraith/javascript/beforeCapture.js
203
208
  - lib/wraith/javascript/casper.js
204
209
  - lib/wraith/javascript/customHeight.js
205
210
  - lib/wraith/javascript/nojs.js
@@ -209,11 +214,13 @@ files:
209
214
  - lib/wraith/thumbnails.rb
210
215
  - lib/wraith/version.rb
211
216
  - lib/wraith/wraith.rb
217
+ - spec/base/global.png
218
+ - spec/base/path.png
219
+ - spec/helpers.rb
220
+ - spec/js/global.js
221
+ - spec/js/path.js
212
222
  - spec/wraith_spec.rb
213
- - templates/configs/component.yaml
214
- - templates/configs/config.yaml
215
- - templates/javascript/casper.js
216
- - templates/javascript/snap.js
223
+ - wraith-logo.png
217
224
  - wraith.gemspec
218
225
  homepage: https://github.com/BBC-News/wraith
219
226
  licenses:
@@ -240,4 +247,9 @@ signing_key:
240
247
  specification_version: 4
241
248
  summary: Wraith is a screenshot comparison tool, created by developers at BBC News.
242
249
  test_files:
250
+ - spec/base/global.png
251
+ - spec/base/path.png
252
+ - spec/helpers.rb
253
+ - spec/js/global.js
254
+ - spec/js/path.js
243
255
  - spec/wraith_spec.rb
@@ -1,41 +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/snap.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
- 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
- #Choose how results are displayed, by default alphanumeric. Different screen widths are always grouped.
38
- #alphanumeric - all paths (with, and without, a difference) are shown, sorted by path
39
- #diffs_first - all paths (with, and without, a difference) are shown, sorted by difference size (largest first)
40
- #diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
41
- #mode: diffs_first
@@ -1,25 +0,0 @@
1
- var system = require('system');
2
- var page = require('webpage').create();
3
- var fs = require('fs');
4
- var casper = require("casper").create();
5
-
6
- var url = casper.cli.get(0);
7
- var view_port_width = casper.cli.get(1);
8
- var image_name = casper.cli.get(2);
9
- var selector = casper.cli.get(3);
10
-
11
- casper.start(url, function() {
12
- this.viewport(view_port_width, 1500).then(function(){
13
- this.wait(2000, function() {
14
- if (selector == undefined) {
15
- this.capture(image_name);
16
- }
17
- else {
18
- this.captureSelector(image_name, selector);
19
- }
20
- console.log('Snapping ' + url + ' at width ' + view_port_width);
21
- });
22
- });
23
- });
24
-
25
- casper.run();
@@ -1,85 +0,0 @@
1
- var system = require('system');
2
- var page = require('webpage').create();
3
- var fs = require('fs');
4
-
5
- if (system.args.length === 3) {
6
- console.log('Usage: snap.js <some URL> <view port width> <target image name>');
7
- phantom.exit();
8
- }
9
-
10
- var url = system.args[1];
11
- var image_name = system.args[3];
12
- var view_port_width = system.args[2];
13
- var current_requests = 0;
14
- var last_request_timeout;
15
- var final_timeout;
16
-
17
-
18
- page.viewportSize = { width: view_port_width, height: 1500};
19
- page.settings = { loadImages: true, javascriptEnabled: true };
20
-
21
- // If you want to use additional phantomjs commands, place them here
22
- 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';
23
-
24
- // You can place custom headers here, example below.
25
- // page.customHeaders = {
26
-
27
- // 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
28
-
29
- // };
30
-
31
- // If you want to set a cookie, just add your details below in the following way.
32
-
33
- // phantom.addCookie({
34
- // 'name': 'ckns_policy',
35
- // 'value': '111',
36
- // 'domain': '.bbc.co.uk'
37
- // });
38
- // phantom.addCookie({
39
- // 'name': 'locserv',
40
- // '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',
41
- // 'domain': '.bbc.co.uk'
42
- // });
43
-
44
- page.onResourceRequested = function(req) {
45
- current_requests += 1;
46
- };
47
-
48
- page.onResourceReceived = function(res) {
49
- if (res.stage === 'end') {
50
- current_requests -= 1;
51
- debounced_render();
52
- }
53
- };
54
-
55
- page.open(url, function(status) {
56
- if (status !== 'success') {
57
- console.log('Error with page ' + url);
58
- phantom.exit();
59
- }
60
- });
61
-
62
-
63
- function debounced_render() {
64
- clearTimeout(last_request_timeout);
65
- clearTimeout(final_timeout);
66
-
67
- // If there's no more ongoing resource requests, wait for 1 second before
68
- // rendering, just in case the page kicks off another request
69
- if (current_requests < 1) {
70
- clearTimeout(final_timeout);
71
- last_request_timeout = setTimeout(function() {
72
- console.log('Snapping ' + url + ' at width ' + view_port_width);
73
- page.render(image_name);
74
- phantom.exit();
75
- }, 1000);
76
- }
77
-
78
- // Sometimes, straggling requests never make it back, in which
79
- // case, timeout after 5 seconds and render the page anyway
80
- final_timeout = setTimeout(function() {
81
- console.log('Snapping ' + url + ' at width ' + view_port_width);
82
- page.render(image_name);
83
- phantom.exit();
84
- }, 5000);
85
- }