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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +1 -1
- data/lib/wraith/cli.rb +108 -73
- data/lib/wraith/compare_images.rb +4 -2
- data/lib/wraith/crop.rb +3 -1
- data/lib/wraith/folder.rb +6 -4
- data/lib/wraith/gallery.rb +21 -22
- data/lib/wraith/helpers/capture_options.rb +52 -0
- data/lib/wraith/helpers/custom_exceptions.rb +8 -0
- data/lib/wraith/helpers/logger.rb +20 -0
- data/lib/wraith/helpers/save_metadata.rb +31 -0
- data/lib/wraith/{utilities.rb → helpers/utilities.rb} +5 -4
- data/lib/wraith/javascript/_helper.js +0 -2
- data/lib/wraith/javascript/casper.js +26 -16
- data/lib/wraith/javascript/phantom.js +148 -5
- data/lib/wraith/save_images.rb +28 -104
- data/lib/wraith/spider.rb +12 -5
- data/lib/wraith/thumbnails.rb +0 -2
- data/lib/wraith/validate.rb +98 -0
- data/lib/wraith/version.rb +1 -1
- data/lib/wraith/wraith.rb +19 -12
- data/spec/_helpers.rb +4 -10
- data/spec/before_capture_spec.rb +19 -10
- data/spec/config_spec.rb +2 -9
- data/spec/configs/test_config--casper.yaml +1 -5
- data/spec/construct_command_spec.rb +43 -0
- data/spec/gallery_spec.rb +1 -2
- data/spec/js/custom_snap_file.js +26 -16
- data/spec/js/global.js +2 -1
- data/spec/js/path.js +2 -1
- data/spec/resize_reload_spec.rb +4 -8
- data/spec/save_images_spec.rb +3 -2
- data/spec/validate_spec.rb +76 -0
- data/templates/configs/capture.yaml +61 -0
- data/templates/configs/history.yaml +81 -0
- data/templates/configs/spider.yaml +13 -2
- data/templates/javascript/cookies_and_headers--casper.js +16 -0
- data/templates/javascript/cookies_and_headers--phantom.js +26 -0
- data/templates/javascript/disable_javascript--casper.js +11 -0
- data/templates/javascript/disable_javascript--phantom.js +13 -0
- data/templates/javascript/interact--casper.js +11 -0
- data/templates/javascript/interact--phantom.js +17 -0
- data/templates/javascript/wait--casper.js +8 -0
- data/templates/javascript/wait--phantom.js +8 -0
- data/wraith.gemspec +1 -1
- metadata +27 -14
- data/lib/wraith/javascript/_phantom__common.js +0 -120
- data/lib/wraith/javascript/phantom--nojs.js +0 -6
- data/templates/configs/component.yaml +0 -60
- data/templates/configs/multiple_domains.yaml +0 -53
- data/templates/javascript/beforeCapture--casper_example.js +0 -12
- data/templates/javascript/beforeCapture--phantom_example.js +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da45ef7a6e2d91b95dfd97c78b2a67fbc213aed
|
4
|
+
data.tar.gz: f629294fbf9daf54fda68cd57ab46286161e9f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f314042b1c3b46a96ed5b352ef41eb40ced18f64b2aef0c7498ba563d0d980399a9c38801ee0ce80dd77f198d3c02e92a21aa70ca819b11430d0dd44c1a39279
|
7
|
+
data.tar.gz: 3bc518f1a5ad518a9230f4c77edc859ba31d2a21ac989017692a4234e01373335560511e28a7ad4fe0aca1bd75be27636b4641d27ab6e8475e3ec4055209c6e6
|
data/.travis.yml
CHANGED
@@ -2,6 +2,9 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
+
before_install:
|
6
|
+
- gem update --system 2.4.5 # last known successful Travis build
|
7
|
+
- gem --version
|
5
8
|
script: bundle exec rspec
|
6
9
|
notifications:
|
7
10
|
email:
|
@@ -11,3 +14,4 @@ notifications:
|
|
11
14
|
on_success: never
|
12
15
|
slack:
|
13
16
|
secure: BgRAqwHabAtIBgtApDjyUiND2SNxd4sHMgq4ffnJ+EoMme6RSUAeK0G6LLyaGAk6YcpCeWRGOccEpzai87R3ckv6uycUVGxFcTvPmCEClakbUelWovVEyVT3hPLWznxJ8pz3EVB2+5aJnAsTg5M2ZnYtk3a5C1mrPS+WKceE/Ls=
|
17
|
+
sudo: false
|
data/Gemfile
CHANGED
data/lib/wraith/cli.rb
CHANGED
@@ -7,9 +7,14 @@ require "wraith/folder"
|
|
7
7
|
require "wraith/thumbnails"
|
8
8
|
require "wraith/compare_images"
|
9
9
|
require "wraith/gallery"
|
10
|
+
require "wraith/validate"
|
11
|
+
require "wraith/version"
|
12
|
+
require "wraith/helpers/logger"
|
13
|
+
require "wraith/helpers/utilities"
|
10
14
|
|
11
15
|
class Wraith::CLI < Thor
|
12
16
|
include Thor::Actions
|
17
|
+
include Logging
|
13
18
|
|
14
19
|
attr_accessor :config_name
|
15
20
|
|
@@ -17,127 +22,157 @@ class Wraith::CLI < Thor
|
|
17
22
|
File.expand_path("../../../", __FILE__)
|
18
23
|
end
|
19
24
|
|
25
|
+
# define internal methods which user should not be able to run directly
|
26
|
+
no_commands do
|
27
|
+
def within_acceptable_limits
|
28
|
+
yield
|
29
|
+
rescue CustomError => e
|
30
|
+
logger.error e.message
|
31
|
+
# other errors, such as SystemError, will not be caught nicely and will give a stack trace (which we'd need)
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_for_paths(config_name)
|
35
|
+
spider = Wraith::Spidering.new(config_name)
|
36
|
+
spider.check_for_paths
|
37
|
+
end
|
38
|
+
|
39
|
+
def copy_old_shots(config_name)
|
40
|
+
create = Wraith::FolderManager.new(config_name)
|
41
|
+
create.copy_old_shots
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "validate", "checks your configuration and validates that all required properties exist"
|
46
|
+
def validate(config_name)
|
47
|
+
within_acceptable_limits do
|
48
|
+
wraith = Wraith::Validate.new(config_name).validate
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
20
52
|
desc "setup", "creates config folder and default config"
|
21
53
|
def setup
|
22
|
-
|
23
|
-
|
54
|
+
within_acceptable_limits do
|
55
|
+
directory("templates/configs", "configs")
|
56
|
+
directory("templates/javascript", "javascript")
|
57
|
+
end
|
24
58
|
end
|
25
59
|
|
26
60
|
desc "reset_shots [config_name]", "removes all the files in the shots folder"
|
27
61
|
def reset_shots(config_name)
|
28
|
-
|
29
|
-
|
62
|
+
within_acceptable_limits do
|
63
|
+
reset = Wraith::FolderManager.new(config_name)
|
64
|
+
reset.clear_shots_folder
|
65
|
+
end
|
30
66
|
end
|
31
67
|
|
32
68
|
desc "setup_folders [config_name]", "create folders for images"
|
33
69
|
def setup_folders(config_name)
|
34
|
-
|
35
|
-
|
70
|
+
within_acceptable_limits do
|
71
|
+
create = Wraith::FolderManager.new(config_name)
|
72
|
+
create.create_folders
|
73
|
+
end
|
36
74
|
end
|
37
75
|
|
38
76
|
desc "copy_base_images [config_name]", "copies the required base images over for comparison with latest images"
|
39
77
|
def copy_base_images(config_name)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
desc "make_sure_base_shots_exists [config_name]", "warns user if config is missing base shots"
|
45
|
-
def make_sure_base_shots_exists(config_name)
|
46
|
-
wraith = Wraith::Wraith.new(config_name)
|
47
|
-
if wraith.history_dir.nil?
|
48
|
-
puts "You need to specify a `history_dir` property at #{config_name} before you can run `wraith latest`!"
|
49
|
-
exit 1
|
50
|
-
end
|
51
|
-
if !File.directory?(wraith.history_dir)
|
52
|
-
puts "You need to run `wraith history` at least once before you can run `wraith latest`!"
|
53
|
-
exit 1
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
no_commands do
|
58
|
-
def check_for_paths(config_name)
|
59
|
-
spider = Wraith::Spidering.new(config_name)
|
60
|
-
spider.check_for_paths
|
61
|
-
end
|
62
|
-
|
63
|
-
def copy_old_shots(config_name)
|
64
|
-
create = Wraith::FolderManager.new(config_name)
|
65
|
-
create.copy_old_shots
|
78
|
+
within_acceptable_limits do
|
79
|
+
copy = Wraith::FolderManager.new(config_name)
|
80
|
+
copy.copy_base_images
|
66
81
|
end
|
67
82
|
end
|
68
83
|
|
69
84
|
desc "save_images [config_name]", "captures screenshots"
|
70
85
|
def save_images(config_name, history = false)
|
71
|
-
|
72
|
-
|
73
|
-
|
86
|
+
within_acceptable_limits do
|
87
|
+
logger.info "SAVING IMAGES"
|
88
|
+
save_images = Wraith::SaveImages.new(config_name, history)
|
89
|
+
save_images.save_images
|
90
|
+
end
|
74
91
|
end
|
75
92
|
|
76
93
|
desc "crop_images [config_name]", "crops images to the same height"
|
77
94
|
def crop_images(config_name)
|
78
|
-
|
79
|
-
|
95
|
+
within_acceptable_limits do
|
96
|
+
crop = Wraith::CropImages.new(config_name)
|
97
|
+
crop.crop_images
|
98
|
+
end
|
80
99
|
end
|
81
100
|
|
82
101
|
desc "compare_images [config_name]", "compares images to generate diffs"
|
83
102
|
def compare_images(config_name)
|
84
|
-
|
85
|
-
|
86
|
-
|
103
|
+
within_acceptable_limits do
|
104
|
+
logger.info "COMPARING IMAGES"
|
105
|
+
compare = Wraith::CompareImages.new(config_name)
|
106
|
+
compare.compare_images
|
107
|
+
end
|
87
108
|
end
|
88
109
|
|
89
110
|
desc "generate_thumbnails [config_name]", "create thumbnails for gallery"
|
90
111
|
def generate_thumbnails(config_name)
|
91
|
-
|
92
|
-
|
93
|
-
|
112
|
+
within_acceptable_limits do
|
113
|
+
logger.info "GENERATING THUMBNAILS"
|
114
|
+
thumbs = Wraith::Thumbnails.new(config_name)
|
115
|
+
thumbs.generate_thumbnails
|
116
|
+
end
|
94
117
|
end
|
95
118
|
|
96
119
|
desc "generate_gallery [config_name]", "create page for viewing images"
|
97
120
|
def generate_gallery(config_name, multi = false)
|
98
|
-
|
99
|
-
|
100
|
-
|
121
|
+
within_acceptable_limits do
|
122
|
+
logger.info "GENERATING GALLERY"
|
123
|
+
gallery = Wraith::GalleryGenerator.new(config_name, multi)
|
124
|
+
gallery.generate_gallery
|
125
|
+
end
|
101
126
|
end
|
102
127
|
|
103
|
-
desc "capture [config_name]", "
|
128
|
+
desc "capture [config_name]", "Capture paths against two domains, compare them, generate gallery"
|
104
129
|
def capture(config, multi = false)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
130
|
+
within_acceptable_limits do
|
131
|
+
logger.info Wraith::Validate.new(config).validate('capture')
|
132
|
+
reset_shots(config)
|
133
|
+
check_for_paths(config)
|
134
|
+
setup_folders(config)
|
135
|
+
save_images(config)
|
136
|
+
crop_images(config)
|
137
|
+
compare_images(config)
|
138
|
+
generate_thumbnails(config)
|
139
|
+
generate_gallery(config, multi)
|
140
|
+
end
|
113
141
|
end
|
114
142
|
|
115
143
|
desc "multi_capture [filelist]", "A Batch of Wraith Jobs"
|
116
144
|
def multi_capture(filelist)
|
117
|
-
|
118
|
-
|
119
|
-
|
145
|
+
within_acceptable_limits do
|
146
|
+
config_array = IO.readlines(filelist)
|
147
|
+
config_array.each do |config|
|
148
|
+
capture(config.chomp, true)
|
149
|
+
end
|
120
150
|
end
|
121
151
|
end
|
122
152
|
|
123
153
|
desc "history [config_name]", "Setup a baseline set of shots"
|
124
154
|
def history(config)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
155
|
+
within_acceptable_limits do
|
156
|
+
logger.info Wraith::Validate.new(config).validate('history')
|
157
|
+
reset_shots(config)
|
158
|
+
check_for_paths(config)
|
159
|
+
setup_folders(config)
|
160
|
+
save_images(config)
|
161
|
+
copy_old_shots(config)
|
162
|
+
end
|
130
163
|
end
|
131
164
|
|
132
165
|
desc "latest [config_name]", "Capture new shots to compare with baseline"
|
133
166
|
def latest(config)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
167
|
+
within_acceptable_limits do
|
168
|
+
logger.info Wraith::Validate.new(config).validate('latest')
|
169
|
+
reset_shots(config)
|
170
|
+
save_images(config, true)
|
171
|
+
copy_base_images(config)
|
172
|
+
crop_images(config)
|
173
|
+
compare_images(config)
|
174
|
+
generate_thumbnails(config)
|
175
|
+
generate_gallery(config)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require "wraith"
|
2
|
+
require "wraith/helpers/logger"
|
2
3
|
require "image_size"
|
3
4
|
require "open3"
|
4
5
|
require "parallel"
|
5
6
|
require "shellwords"
|
6
7
|
|
7
8
|
class Wraith::CompareImages
|
9
|
+
include Logging
|
8
10
|
attr_reader :wraith
|
9
11
|
|
10
12
|
def initialize(config)
|
@@ -16,9 +18,9 @@ class Wraith::CompareImages
|
|
16
18
|
Parallel.each(files.each_slice(2), :in_processes => Parallel.processor_count) do |base, compare|
|
17
19
|
diff = base.gsub(/([a-zA-Z0-9]+).png$/, "diff.png")
|
18
20
|
info = base.gsub(/([a-zA-Z0-9]+).png$/, "data.txt")
|
19
|
-
|
21
|
+
logger.info "Comparing #{base} and #{compare}"
|
20
22
|
compare_task(base, compare, diff, info)
|
21
|
-
|
23
|
+
logger.info "Saved diff"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
data/lib/wraith/crop.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "wraith"
|
2
|
+
require "wraith/helpers/logger"
|
2
3
|
require "image_size"
|
3
4
|
require "parallel"
|
4
5
|
require "shellwords"
|
5
6
|
|
6
7
|
class Wraith::CropImages
|
8
|
+
include Logging
|
7
9
|
attr_reader :wraith
|
8
10
|
|
9
11
|
def initialize(config)
|
@@ -14,7 +16,7 @@ class Wraith::CropImages
|
|
14
16
|
files = Dir.glob("#{wraith.directory}/*/*.png").sort
|
15
17
|
|
16
18
|
Parallel.each(files.each_slice(2), :in_processes => Parallel.processor_count) do |base, compare|
|
17
|
-
|
19
|
+
logger.info "cropping images"
|
18
20
|
|
19
21
|
width = image_dimensions(base)[0]
|
20
22
|
base_height = image_dimensions(base)[1]
|
data/lib/wraith/folder.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "wraith"
|
2
|
+
require "wraith/helpers/logger"
|
2
3
|
|
3
4
|
class Wraith::FolderManager
|
5
|
+
include Logging
|
4
6
|
attr_reader :wraith
|
5
7
|
|
6
8
|
def initialize(config)
|
@@ -35,17 +37,17 @@ class Wraith::FolderManager
|
|
35
37
|
|
36
38
|
def copy_old_shots
|
37
39
|
if history_dir.nil?
|
38
|
-
|
40
|
+
logger.error 'no `history_dir` attribute found in config. Cannot copy files.'
|
39
41
|
else
|
40
42
|
FileUtils.cp_r("#{dir}/.", "#{history_dir}/")
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
def copy_base_images
|
45
|
-
|
47
|
+
logger.info "COPYING BASE IMAGES"
|
46
48
|
wraith.paths.each do |path|
|
47
49
|
path = path[0]
|
48
|
-
|
50
|
+
logger.info "Copying #{history_dir}/#{path} to #{dir}"
|
49
51
|
FileUtils.cp_r(Dir.glob("#{history_dir}/#{path}"), dir)
|
50
52
|
end
|
51
53
|
end
|
@@ -60,7 +62,7 @@ class Wraith::FolderManager
|
|
60
62
|
FileUtils.mkdir_p("#{dir}/thumbnails/#{folder_label}")
|
61
63
|
FileUtils.mkdir_p("#{dir}/#{folder_label}")
|
62
64
|
end
|
63
|
-
|
65
|
+
logger.info "Creating Folders"
|
64
66
|
end
|
65
67
|
|
66
68
|
def tidy_shots_folder(dirs)
|
data/lib/wraith/gallery.rb
CHANGED
@@ -2,8 +2,10 @@ require "erb"
|
|
2
2
|
require "pp"
|
3
3
|
require "fileutils"
|
4
4
|
require "wraith/wraith"
|
5
|
+
require "wraith/helpers/logger"
|
5
6
|
|
6
7
|
class Wraith::GalleryGenerator
|
8
|
+
include Logging
|
7
9
|
attr_reader :wraith
|
8
10
|
|
9
11
|
MATCH_FILENAME = /(\S+)_(\S+)\.\S+/
|
@@ -35,9 +37,7 @@ class Wraith::GalleryGenerator
|
|
35
37
|
|
36
38
|
Dir.foreach("#{dirname}/#{category}") do |filename|
|
37
39
|
match = MATCH_FILENAME.match(filename)
|
38
|
-
unless match.nil?
|
39
|
-
matcher(match, filename, dirname, category)
|
40
|
-
end
|
40
|
+
matcher(match, filename, dirname, category) unless match.nil?
|
41
41
|
end
|
42
42
|
end
|
43
43
|
@folder_manager.tidy_shots_folder(@dirs)
|
@@ -76,10 +76,7 @@ class Wraith::GalleryGenerator
|
|
76
76
|
def get_group_from_match(match)
|
77
77
|
group = match[2]
|
78
78
|
dash = match[2].rindex('-')
|
79
|
-
|
80
|
-
if !dash.nil?
|
81
|
-
group = match[2][dash+1..-1]
|
82
|
-
end
|
79
|
+
group = match[2][dash+1..-1] unless dash.nil?
|
83
80
|
group
|
84
81
|
end
|
85
82
|
|
@@ -123,6 +120,16 @@ class Wraith::GalleryGenerator
|
|
123
120
|
Hash[@sorted]
|
124
121
|
end
|
125
122
|
|
123
|
+
def generate_gallery(with_path = "")
|
124
|
+
dest = "#{@location}/gallery.html"
|
125
|
+
directories = parse_directories(@location)
|
126
|
+
|
127
|
+
template = File.expand_path("gallery_template/#{wraith.gallery_template}.erb", File.dirname(__FILE__))
|
128
|
+
generate_html(@location, directories, template, dest, with_path)
|
129
|
+
|
130
|
+
report_gallery_status dest
|
131
|
+
end
|
132
|
+
|
126
133
|
def generate_html(location, directories, template, destination, path)
|
127
134
|
template = File.read(template)
|
128
135
|
locals = {
|
@@ -130,7 +137,6 @@ class Wraith::GalleryGenerator
|
|
130
137
|
:directories => directories,
|
131
138
|
:path => path,
|
132
139
|
:threshold => wraith.threshold
|
133
|
-
|
134
140
|
}
|
135
141
|
html = ERB.new(template).result(ErbBinding.new(locals).get_binding)
|
136
142
|
File.open(destination, "w") do |outf|
|
@@ -138,15 +144,8 @@ class Wraith::GalleryGenerator
|
|
138
144
|
end
|
139
145
|
end
|
140
146
|
|
141
|
-
def
|
142
|
-
|
143
|
-
directories = parse_directories(@location)
|
144
|
-
|
145
|
-
slideshow_template = File.expand_path("gallery_template/#{wraith.gallery_template}.erb", File.dirname(__FILE__))
|
146
|
-
|
147
|
-
generate_html(@location, directories, slideshow_template, dest, with_path)
|
148
|
-
|
149
|
-
puts "Gallery generated"
|
147
|
+
def report_gallery_status(dest)
|
148
|
+
logger.info "Gallery generated"
|
150
149
|
failed = check_failed_shots
|
151
150
|
prompt_user_to_open_gallery dest
|
152
151
|
exit 1 if failed
|
@@ -156,15 +155,15 @@ class Wraith::GalleryGenerator
|
|
156
155
|
if @multi
|
157
156
|
return false
|
158
157
|
elsif @failed_shots == false
|
159
|
-
|
158
|
+
logger.warn "Failures detected:"
|
160
159
|
|
161
160
|
@dirs.each do |dir, sizes|
|
162
161
|
sizes.to_a.sort.each do |size, files|
|
163
162
|
file = dir.gsub('__', '/')
|
164
163
|
if !files.include?(:diff)
|
165
|
-
|
164
|
+
logger.warn "\t Unable to create a diff image for #{file}"
|
166
165
|
elsif files[:data] > wraith.threshold
|
167
|
-
|
166
|
+
logger.warn "\t #{file} failed at a resolution of #{size} (#{files[:data]}% diff)"
|
168
167
|
end
|
169
168
|
end
|
170
169
|
end
|
@@ -176,8 +175,8 @@ class Wraith::GalleryGenerator
|
|
176
175
|
end
|
177
176
|
|
178
177
|
def prompt_user_to_open_gallery(dest)
|
179
|
-
|
180
|
-
|
178
|
+
logger.info "\nView the gallery in your browser:"
|
179
|
+
logger.info "\t file://" + Dir.pwd + '/' + dest
|
181
180
|
end
|
182
181
|
|
183
182
|
class ErbBinding < OpenStruct
|