wraith 2.0.1 → 2.1.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: bffb240ff47827e94e770a300822e1050c915251
4
- data.tar.gz: d3a59402c518cbf852de2e7817deefdb037e19b9
3
+ metadata.gz: bc1b08d5b7dbe5e6347a8a661f82560cef5552ea
4
+ data.tar.gz: 259f28a58b73bf17ff37902636b9bcfb70e836a9
5
5
  SHA512:
6
- metadata.gz: 2a0d90f1be903f814b696930aec7b4fae86a394ca80882cd49e97cccf894b9ed598571f0553b5fee282e9f7d16a635ff3edb9e856d1a74b037bdeff2f45ec7df
7
- data.tar.gz: 2d1894f2ec8515af641c0f6eee94e4b8fdda15efa5f5ca9bab9f52a412dc5dc55d793a3b4513f1d124ded37cbd9ecde64b432b57217394a0e318d0392b6c23b7
6
+ metadata.gz: 9bf5dc5c91429da67d420246b3b11ea16f260836a9aeccd0e20fbdc249c380d66f2848a475bb440ed53f6e5fdf904cc2a63a665aadf24037089ea5b03edb2a60
7
+ data.tar.gz: f1e2400695398f549b49d438f0f33dd6e176e8d6524eca2004ed3057d362854194da4956da298ddf38abbd564d8b9ce942626de3796d4b080d8f90c5d15ecfd8
data/Dockerfile ADDED
@@ -0,0 +1,14 @@
1
+ FROM ruby:2.1.2
2
+
3
+ # some of ruby's build scripts are written in ruby
4
+ # we purge this later to make sure our final image uses what we just built
5
+ RUN apt-get update
6
+ RUN curl -o phantomjs.tar.gz -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
7
+ RUN tar -xvf phantomjs.tar.gz
8
+ RUN mv phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin
9
+ RUN echo "export phantomjs=/usr/bin/phantomjs" > .bashrc
10
+ RUN apt-get install -y libfreetype6 libfontconfig1
11
+ RUN gem install wraith --no-rdoc --no-ri
12
+ RUN gem install aws-sdk --no-rdoc --no-ri
13
+
14
+ ENTRYPOINT [ "wraith" ]
data/README.md CHANGED
@@ -11,8 +11,8 @@ Wraith is a screenshot comparison tool, created by developers at BBC News.
11
11
 
12
12
  ## What is it?
13
13
 
14
- Wraith uses either [PhantomJS](http://phantomjs.org) or
15
- [SlimerJS](http://slimerjs.org) to create screen-shots of different environments
14
+ Wraith uses either [PhantomJS](http://phantomjs.org), [CasperJS](http://casperjs.org/) or
15
+ [SlimerJS](http://slimerjs.org) to create screen-shots of webpages on different environments
16
16
  and then creates a diff of the two images, the affected areas are highlighted in
17
17
  blue
18
18
 
@@ -22,7 +22,12 @@ diff](http://bbc-news.github.io/wraith/img/320_diff.png)
22
22
 
23
23
  ## Requirements
24
24
 
25
- Imagemagick and PhantomJS are required to use Wraith, install via your favourite package manager. 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)
25
+ 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)
26
+
27
+ ```sh
28
+ brew install phantomjs
29
+ brew install imagemagick
30
+ ```
26
31
 
27
32
  ## Installation
28
33
 
@@ -69,6 +74,7 @@ There are other commands also available, these all expect a config_name to be pa
69
74
  wraith reset_shots [config_name] # removes all the files in the shots folder
70
75
  wraith save_images [config_name] # captures screenshots
71
76
  wraith setup # creates config folder and default config
77
+ wraith setup_casper # creates config folder and default config for casper
72
78
  wraith setup_folders [config_name] # create folders for images
73
79
  ```
74
80
 
@@ -80,11 +86,21 @@ After each screenshot is captured, the compare task will run, this will output a
80
86
 
81
87
  A gallery is available to view each of the images and the respective diff images located in the shots folder once all the images have been compared.
82
88
 
89
+ ## CasperJS
90
+
91
+ There is an example [component config file](https://github.com/BBC-News/wraith/blob/master/configs/component.yaml) which indicates how to target a specific selector on a page. Pass in a label for the shot, path and selector. This will be handed to CasperJS and will only screenshot that component on the page. This is faster way to verify smaller changes to specific components during development. You must install [CasperJS](http://casperjs.org/) to use.
92
+
93
+ For a quick setup for CasperJS, you can run :
94
+
95
+ ```sh
96
+ wraith setup_casper
97
+ ```
98
+
83
99
  ## History usage
84
100
 
85
101
  In Wraith 2.0 we introduced a new way for using Wraith in development and testing, historical shots. Rather than capture 2 domains, you capture 1 domain, probably your local copy of the latest code, then later on after development is in progress, run Wraith again to compare. This makes working against an isolated dev environment much easier as you wont need an internet connection.
86
102
 
87
- The usage is different in that you need 1 domain in your config and you will need to set a historical shots folder. An example of this can be found on Github. The way this works is that shots are captured as normal with the history command below. This will create 2 folders with the labels you have specified in the config file, for example, shots and shots_history. The original shots will be copied into your 'history' folder, then copied back into the shots folder once you have run your latest job. This workflow will essentially mean your history folder is your baseline, being copied back into the shots folder every time you run the 'latest command'
103
+ The usage is different in that you need 1 domain in your config and you will need to set a historical shots folder. You will need to specify a `history_dir` in addition to the `directory` key in your `config.yml` file. An example of this can be found in the [`history.yaml`](https://github.com/BBC-News/wraith/blob/31406956bfc465d087f1d40304630e18dc0f857e/configs/history.yaml#L9-L11) file of the `configs` directory of this repository. The way this works is that shots are captured as normal with the history command below. This will create 2 folders with the labels you have specified in the config file, for example, shots and shots_history. The original shots will be copied into your 'history' folder, then copied back into the shots folder once you have run your latest job. This workflow will essentially mean your history folder is your baseline, being copied back into the shots folder every time you run the 'latest command'
88
104
 
89
105
  ```sh
90
106
  wraith history history.yaml
@@ -95,9 +111,18 @@ wraith latest history.yaml
95
111
  ```
96
112
  You will now be able to run the latest command over and over without having to do clear up.
97
113
 
98
- ## Changelog - updated 2014-09-25
99
- Wraith 2.0 with new history support, this is a big change for the usage of Wraith, with less dependency on having an Internet connection and capturing two domains.
100
- A large change in the way file names are made has been introduced into 2.0, with the label of the engine now being used instead of the engine string itself. This has been updated in all the included configs for reference, but will mean a change to the filenames and urls. We have also changed the way that folders are loaded from the config, dropping the use of arrays. This is backward compatible.
114
+ ## Docker
115
+ At BBC, we use Docker and AWS in our workflow. The Dockerfile is in the repo, but you can pull from the registry here`docker pull bbcnews/wraith`. There is no quick way to get up and running with OSX and no way to use it on Windows. For a CI environment, it has a really good use case though. To run, specify your workspace and the command you want. If you want to use the Ruby AWS-SDK gem to upload your images to s3, it is built into the container. I recommend writing a simple ruby script that runs once you have completed a Wraith run.
116
+
117
+ ```sh
118
+ docker run -d bbcnews/wraith -w /wraith -v path/to/dir:/wraith capture configs/config.yaml
119
+ ```
120
+
121
+ ## Changelog - updated 2014-10-20
122
+ We have combined CasperJS with Wraith to enable component screen shots and comparison. This allows for developers to check only a small part of a page for regressions allowing for quicker and smaller screenshots.
123
+
124
+
125
+ Notice : We have deprecated the ability to not use labels on URLs in config files and have Wraith create them for you. Ensure that you update your config with labels before running again.
101
126
 
102
127
  ## Contributing
103
128
 
@@ -0,0 +1,45 @@
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
+ russian: "http://www.bbc.co.uk/russian"
15
+ arabic: "http://www.bbc.co.uk/arabic"
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
data/lib/wraith/cli.rb CHANGED
@@ -23,6 +23,12 @@ class Wraith::CLI < Thor
23
23
  template('javascript/snap.js', 'javascript/snap.js')
24
24
  end
25
25
 
26
+ desc 'setup_casper', 'creates config folder and default config for casper'
27
+ def setup_casper
28
+ template('configs/component.yaml', 'configs/component.yaml')
29
+ template('javascript/casper.js', 'javascript/casper.js')
30
+ end
31
+
26
32
  desc 'reset_shots [config_name]', 'removes all the files in the shots folder'
27
33
  def reset_shots(config_name)
28
34
  reset = Wraith::FolderManager.new(config_name)
@@ -0,0 +1,20 @@
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
+ this.captureSelector(image_name, selector);
15
+ console.log('Snapping ' + url + ' at width ' + view_port_width);
16
+ });
17
+ });
18
+ });
19
+
20
+ casper.run();
@@ -46,9 +46,9 @@ class Wraith::SaveImages
46
46
  "#{directory}/#{label}/#{width}_#{engine_label}_#{domain_label}.png"
47
47
  end
48
48
 
49
- def attempt_image_capture(width, url, filename, max_attempts)
49
+ def attempt_image_capture(width, url, filename, selector, max_attempts)
50
50
  max_attempts.times do |i|
51
- capture_page_image engine, url, width, filename
51
+ capture_page_image engine, url, width, filename, selector
52
52
 
53
53
  return if File.exist? filename
54
54
 
@@ -58,13 +58,19 @@ class Wraith::SaveImages
58
58
  fail "Unable to capture image #{filename} after #{max_attempts} attempt(s)"
59
59
  end
60
60
 
61
+ def has_casper(options)
62
+ options['path'] ? options['path'] : options
63
+ end
64
+
65
+ def casper_selector(options)
66
+ options['selector'] ? options['selector'] : ' '
67
+ end
68
+
61
69
  def save_images
62
70
  jobs = []
63
- check_paths.each do |label, path|
64
- unless path
65
- path = label
66
- label = path.gsub('/', '__')
67
- end
71
+ check_paths.each do |label, options|
72
+ path = has_casper(options)
73
+ selector = casper_selector(options)
68
74
 
69
75
  base_url = base_urls(path)
70
76
  compare_url = compare_urls(path)
@@ -73,17 +79,17 @@ class Wraith::SaveImages
73
79
  base_file_name = file_names(width, label, "#{wraith.base_domain_label}#{history_label}")
74
80
  compare_file_name = file_names(width, label, "#{wraith.comp_domain_label}#{history_label}")
75
81
 
76
- jobs << [label, path, width, base_url, base_file_name]
77
- jobs << [label, path, width, compare_url, compare_file_name] unless compare_url.nil?
82
+ jobs << [label, path, width, base_url, base_file_name, selector]
83
+ jobs << [label, path, width, compare_url, compare_file_name, selector] unless compare_url.nil?
78
84
  end
79
85
  end
80
86
  parallel_task(jobs)
81
87
  end
82
88
 
83
89
  def parallel_task(jobs)
84
- Parallel.each(jobs, in_threads: 8) do |_label, _path, width, url, filename|
90
+ Parallel.each(jobs, in_threads: 8) do |_label, _path, width, url, filename, selector|
85
91
  begin
86
- attempt_image_capture(width, url, filename, 5)
92
+ attempt_image_capture(width, url, filename, selector, 5)
87
93
  rescue => e
88
94
  puts e
89
95
 
@@ -101,7 +107,7 @@ class Wraith::SaveImages
101
107
  `convert #{image} -background none -extent #{width}x0 #{image}`
102
108
  end
103
109
 
104
- def capture_page_image(browser, url, width, file_name)
105
- puts `"#{browser}" "#{wraith.phantomjs_options}" "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}"`
110
+ def capture_page_image(browser, url, width, file_name, selector)
111
+ puts `"#{browser}" "#{wraith.phantomjs_options}" "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}" "#{selector}"`
106
112
  end
107
113
  end
data/lib/wraith/spider.rb CHANGED
@@ -57,6 +57,7 @@ class Wraith::Crawler < Wraith::Spider
57
57
  def spider
58
58
  if File.exist?(@wraith.spider_file) && modified_since(@wraith.spider_file, @wraith.spider_days[0])
59
59
  puts 'using existing spider file'
60
+ @paths = eval(File.read(@wraith.spider_file))
60
61
  else
61
62
  puts 'creating new spider file'
62
63
  spider_list = []
@@ -1,3 +1,3 @@
1
1
  module Wraith
2
- VERSION = '2.0.1'
2
+ VERSION = '2.1.0'
3
3
  end
data/spec/wraith_spec.rb CHANGED
@@ -3,16 +3,17 @@ require 'image_size'
3
3
  require './lib/wraith/cli'
4
4
 
5
5
  describe Wraith do
6
- Given(:config_name) { 'test_config' }
7
6
  Given { Wraith::FolderManager.new(config_name).clear_shots_folder }
8
- Given(:test_url1) { 'http://www.live.bbc.co.uk/news' }
9
- Given(:test_url2) { 'http://www.live.bbc.co.uk/russian' }
10
7
  Given { Dir.mkdir('shots/test') }
11
- Given(:test_image1) { 'shots/test/test1.png' }
12
- Given(:test_image2) { 'shots/test/test2.png' }
13
- Given(:diff_image) { 'shots/test/test_diff.png' }
14
- Given(:data_txt) { 'shots/test/test.txt' }
15
- Given(:saving) { Wraith::SaveImages.new(config_name) }
8
+ let(:config_name) { 'test_config' }
9
+ let(:test_url1) { 'http://www.live.bbc.co.uk/news' }
10
+ let(:test_url2) { 'http://www.live.bbc.co.uk/russian' }
11
+ let(:test_image1) { 'shots/test/test1.png' }
12
+ let(:test_image2) { 'shots/test/test2.png' }
13
+ let(:diff_image) { 'shots/test/test_diff.png' }
14
+ let(:data_txt) { 'shots/test/test.txt' }
15
+ let(:selector) { ''}
16
+ let(:saving) { Wraith::SaveImages.new(config_name) }
16
17
 
17
18
  When(:wraith) { Wraith::Wraith.new(config_name) }
18
19
  Then { wraith.is_a? Wraith::Wraith }
@@ -32,7 +33,7 @@ describe Wraith do
32
33
  # capture_page_image
33
34
  When do
34
35
  wraith.engine.each do |_type, engine|
35
- saving.capture_page_image(engine, test_url1, 320, test_image1)
36
+ saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
36
37
  end
37
38
  end
38
39
  When(:image_size) { ImageSize.path(test_image1).size }
@@ -42,8 +43,8 @@ describe Wraith do
42
43
  context 'When comparing images' do
43
44
  When(:diff_image_size) do
44
45
  wraith.engine.each do |_type, engine|
45
- saving.capture_page_image(engine, test_url1, 320, test_image1)
46
- saving.capture_page_image(engine, test_url2, 320, test_image2)
46
+ saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
47
+ saving.capture_page_image(engine, test_url2, 320, test_image2, selector)
47
48
  end
48
49
  Wraith::CropImages.new(config_name).crop_images
49
50
  Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
@@ -55,8 +56,8 @@ describe Wraith do
55
56
  context 'When generating tumbnails' do
56
57
  When do
57
58
  wraith.engine.each do |_type, engine|
58
- saving.capture_page_image(engine, test_url1, 320, test_image1)
59
- saving.capture_page_image(engine, test_url2, 320, test_image2)
59
+ saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
60
+ saving.capture_page_image(engine, test_url2, 320, test_image2, selector)
60
61
  end
61
62
  Wraith::CropImages.new(config_name).crop_images
62
63
  Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
@@ -0,0 +1,45 @@
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
+ russian: "http://www.bbc.co.uk/russian"
15
+ arabic: "http://www.bbc.co.uk/arabic"
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
@@ -0,0 +1,20 @@
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
+ this.captureSelector(image_name, selector);
15
+ console.log('Snapping ' + url + ' at width ' + view_port_width);
16
+ });
17
+ });
18
+ });
19
+
20
+ casper.run();
data/wraith.gemspec CHANGED
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency 'log4r'
30
30
  spec.add_runtime_dependency 'thor'
31
31
  spec.add_runtime_dependency 'parallel'
32
+ spec.add_runtime_dependency 'casperjs'
32
33
  end
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.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Blooman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-26 00:00:00.000000000 Z
12
+ date: 2014-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -151,6 +151,20 @@ dependencies:
151
151
  - - '>='
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: casperjs
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
154
168
  description: Wraith is a screenshot comparison tool, created by developers at BBC
155
169
  News.
156
170
  email:
@@ -165,12 +179,14 @@ files:
165
179
  - .gitignore
166
180
  - .ruby-version
167
181
  - .travis.yml
182
+ - Dockerfile
168
183
  - Gemfile
169
184
  - LICENSE
170
185
  - README.md
171
186
  - Rakefile
172
187
  - assets/invalid.jpg
173
188
  - bin/wraith
189
+ - configs/component.yaml
174
190
  - configs/config.yaml
175
191
  - configs/config_nojs.yaml
176
192
  - configs/history.yaml
@@ -183,6 +199,7 @@ files:
183
199
  - lib/wraith/gallery.rb
184
200
  - lib/wraith/gallery_template/bootstrap.min.css
185
201
  - lib/wraith/gallery_template/gallery_template.erb
202
+ - lib/wraith/javascript/casper.js
186
203
  - lib/wraith/javascript/nojs.js
187
204
  - lib/wraith/javascript/snap.js
188
205
  - lib/wraith/save_images.rb
@@ -191,7 +208,9 @@ files:
191
208
  - lib/wraith/version.rb
192
209
  - lib/wraith/wraith.rb
193
210
  - spec/wraith_spec.rb
211
+ - templates/configs/component.yaml
194
212
  - templates/configs/config.yaml
213
+ - templates/javascript/casper.js
195
214
  - templates/javascript/snap.js
196
215
  - wraith.gemspec
197
216
  homepage: https://github.com/BBC-News/wraith