wraith 2.3.2 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +120 -0
- data/Gemfile +1 -1
- data/README.md +5 -3
- data/Rakefile +22 -22
- data/bin/wraith +1 -1
- data/lib/wraith.rb +2 -2
- data/lib/wraith/cli.rb +28 -27
- data/lib/wraith/compare_images.rb +10 -10
- data/lib/wraith/crop.rb +6 -6
- data/lib/wraith/folder.rb +5 -5
- data/lib/wraith/gallery.rb +25 -25
- data/lib/wraith/save_images.rb +96 -58
- data/lib/wraith/spider.rb +13 -13
- data/lib/wraith/thumbnails.rb +5 -5
- data/lib/wraith/version.rb +1 -1
- data/lib/wraith/wraith.rb +20 -20
- data/spec/wraith_spec.rb +94 -46
- data/templates/javascript/casper.js +6 -1
- data/wraith.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f06fef6c1584ea8502744988e405e3717a5a1fb
|
4
|
+
data.tar.gz: 47f3489629f192b949277048a330f29e7e0df729
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9d9dbf50a36715eb9f0f00720c84546624467c3d547ef9800a904661895e87f17c56751dd8cde11dc62139d79e4d90af65c12f267f6e6a9cf0b6712fe7effa8
|
7
|
+
data.tar.gz: 45c9b9c474a35147cd732a948cdd091691378e150961b3ab00d0b065d58ba34a755e7e861e8d81d732291f7075b4e1eab722738f409deed60a85db6aec9e77c2
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "**/*.gemspec"
|
4
|
+
|
5
|
+
Lint/SpaceBeforeFirstArg:
|
6
|
+
Severity: fatal
|
7
|
+
Enabled: true
|
8
|
+
|
9
|
+
Lint/RescueException:
|
10
|
+
Severity: fatal
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Lint/UnusedBlockArgument:
|
14
|
+
Severity: fatal
|
15
|
+
Enabled: true
|
16
|
+
|
17
|
+
Metrics/LineLength:
|
18
|
+
Severity: fatal
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Severity: convention
|
23
|
+
Enabled: true
|
24
|
+
Max: 5
|
25
|
+
|
26
|
+
Style/AlignHash:
|
27
|
+
Severity: fatal
|
28
|
+
Enabled: true
|
29
|
+
EnforcedHashRocketStyle: table
|
30
|
+
|
31
|
+
Style/AlignParameters:
|
32
|
+
Severity: fatal
|
33
|
+
Enabled: true
|
34
|
+
EnforcedStyle: with_fixed_indentation
|
35
|
+
|
36
|
+
Style/BracesAroundHashParameters:
|
37
|
+
Severity: fatal
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
ClassAndModuleChildren:
|
41
|
+
Severity: fatal
|
42
|
+
Enabled: true
|
43
|
+
|
44
|
+
Style/ConstantName:
|
45
|
+
Severity: fatal
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Style/Documentation:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Style/EmptyLinesAroundClassBody:
|
52
|
+
Severity: fatal
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
Style/ExtraSpacing:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/FileName:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/HashSyntax:
|
62
|
+
Severity: fatal
|
63
|
+
Enabled: true
|
64
|
+
EnforcedStyle: hash_rockets
|
65
|
+
|
66
|
+
Style/IndentationConsistency:
|
67
|
+
Severity: fatal
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
Style/IndentationWidth:
|
71
|
+
Severity: fatal
|
72
|
+
Enabled: true
|
73
|
+
|
74
|
+
Style/IndentHash:
|
75
|
+
Severity: fatal
|
76
|
+
Enabled: true
|
77
|
+
|
78
|
+
Style/InlineComment:
|
79
|
+
Severity: fatal
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Style/LineEndConcatenation:
|
83
|
+
Severity: fatal
|
84
|
+
Enabled: true
|
85
|
+
|
86
|
+
Style/MethodName:
|
87
|
+
Severity: fatal
|
88
|
+
Enabled: true
|
89
|
+
|
90
|
+
Style/MultilineTernaryOperator:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
Style/NegatedIf:
|
94
|
+
Severity: fatal
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
Style/Not:
|
98
|
+
Severity: fatal
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
Style/SpaceInsideHashLiteralBraces:
|
102
|
+
Severity: fatal
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
Style/StringLiterals:
|
106
|
+
Severity: fatal
|
107
|
+
Enabled: true
|
108
|
+
EnforcedStyle: double_quotes
|
109
|
+
|
110
|
+
Style/TrailingBlankLines:
|
111
|
+
Severity: fatal
|
112
|
+
Enabled: true
|
113
|
+
|
114
|
+
Style/TrailingWhitespace:
|
115
|
+
Severity: fatal
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
Style/VariableName:
|
119
|
+
Severity: fatal
|
120
|
+
Enabled: true
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Wraith
|
2
2
|
|
3
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)
|
4
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)
|
5
7
|
|
6
8
|
* Website: http://responsivenews.co.uk
|
7
9
|
* Source: http://github.com/bbc-news/wraith
|
@@ -108,9 +110,9 @@ Take a look at the LICENSE file in the code.
|
|
108
110
|
|
109
111
|
## Credits
|
110
112
|
|
111
|
-
* [Dave Blooman](
|
112
|
-
* [John Cleveley](
|
113
|
-
* [Simon Thulbourn](
|
113
|
+
* [Dave Blooman](https://twitter.com/dblooman)
|
114
|
+
* [John Cleveley](https://twitter.com/jcleveley)
|
115
|
+
* [Simon Thulbourn](https://twitter.com/sthulb)
|
114
116
|
|
115
117
|
## Selenium-Wraith
|
116
118
|
|
data/Rakefile
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__),
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "wraith/save_images"
|
5
|
+
require "wraith/crop"
|
6
|
+
require "wraith/spider"
|
7
|
+
require "wraith/folder"
|
8
|
+
require "wraith/thumbnails"
|
9
|
+
require "wraith/compare_images"
|
10
|
+
require "wraith/gallery"
|
11
11
|
|
12
|
-
@config = (
|
12
|
+
@config = ("config")
|
13
13
|
|
14
|
-
desc
|
14
|
+
desc "Execute wraith on two sites with a config you specify"
|
15
15
|
task :config, [:yaml] do |_t, custom|
|
16
|
-
custom.with_defaults(yaml
|
16
|
+
custom.with_defaults(:yaml => "config")
|
17
17
|
@config = "#{custom[:yaml]}"
|
18
|
-
Rake::Task[
|
18
|
+
Rake::Task["default"].invoke
|
19
19
|
end
|
20
20
|
|
21
|
-
task default
|
22
|
-
puts
|
21
|
+
task :default => [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :crop_images, :compare_images, :generate_thumbnails, :generate_gallery] do
|
22
|
+
puts "Done!"
|
23
23
|
end
|
24
24
|
|
25
25
|
task :reset_shots_folder do
|
@@ -58,18 +58,18 @@ task :generate_thumbnails do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
task :generate_gallery do
|
61
|
-
gallery = Wraith::GalleryGenerator.new(@config)
|
61
|
+
gallery = Wraith::GalleryGenerator.new(@config, false)
|
62
62
|
gallery.generate_gallery
|
63
63
|
end
|
64
64
|
|
65
|
-
desc
|
65
|
+
desc "Execute wraith on a single site, no image diffs, with a config you specify"
|
66
66
|
task :grabber, [:yaml] do |_t, custom|
|
67
|
-
custom.with_defaults(yaml
|
67
|
+
custom.with_defaults(:yaml => "config")
|
68
68
|
@config = "#{custom[:yaml]}"
|
69
|
-
Rake::Task[
|
69
|
+
Rake::Task["grab"].invoke
|
70
70
|
end
|
71
71
|
|
72
|
-
desc
|
73
|
-
task grab
|
74
|
-
puts
|
72
|
+
desc "Execute wraith on a single site, no image diffs"
|
73
|
+
task :grab => [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :generate_thumbnails, :generate_gallery] do
|
74
|
+
puts "Done!"
|
75
75
|
end
|
data/bin/wraith
CHANGED
data/lib/wraith.rb
CHANGED
data/lib/wraith/cli.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
require "thor"
|
2
|
+
require "wraith"
|
3
|
+
require "wraith/save_images"
|
4
|
+
require "wraith/crop"
|
5
|
+
require "wraith/spider"
|
6
|
+
require "wraith/folder"
|
7
|
+
require "wraith/thumbnails"
|
8
|
+
require "wraith/compare_images"
|
9
|
+
require "wraith/gallery"
|
10
10
|
|
11
11
|
class Wraith::CLI < Thor
|
12
12
|
include Thor::Actions
|
@@ -14,28 +14,28 @@ class Wraith::CLI < Thor
|
|
14
14
|
attr_accessor :config_name
|
15
15
|
|
16
16
|
def self.source_root
|
17
|
-
File.expand_path(
|
17
|
+
File.expand_path("../../../templates/", __FILE__)
|
18
18
|
end
|
19
19
|
|
20
|
-
desc
|
20
|
+
desc "setup", "creates config folder and default config"
|
21
21
|
def setup
|
22
|
-
template(
|
23
|
-
template(
|
22
|
+
template("configs/config.yaml", "configs/config.yaml")
|
23
|
+
template("javascript/snap.js", "javascript/snap.js")
|
24
24
|
end
|
25
25
|
|
26
|
-
desc
|
26
|
+
desc "setup_casper", "creates config folder and default config for casper"
|
27
27
|
def setup_casper
|
28
|
-
template(
|
29
|
-
template(
|
28
|
+
template("configs/component.yaml", "configs/component.yaml")
|
29
|
+
template("javascript/casper.js", "javascript/casper.js")
|
30
30
|
end
|
31
31
|
|
32
|
-
desc
|
32
|
+
desc "reset_shots [config_name]", "removes all the files in the shots folder"
|
33
33
|
def reset_shots(config_name)
|
34
34
|
reset = Wraith::FolderManager.new(config_name)
|
35
35
|
reset.clear_shots_folder
|
36
36
|
end
|
37
37
|
|
38
|
-
desc
|
38
|
+
desc "setup_folders [config_name]", "create folders for images"
|
39
39
|
def setup_folders(config_name)
|
40
40
|
create = Wraith::FolderManager.new(config_name)
|
41
41
|
create.create_folders
|
@@ -58,37 +58,37 @@ class Wraith::CLI < Thor
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
desc
|
61
|
+
desc "save_images [config_name]", "captures screenshots"
|
62
62
|
def save_images(config_name, history = false)
|
63
63
|
save_images = Wraith::SaveImages.new(config_name, history)
|
64
64
|
save_images.save_images
|
65
65
|
end
|
66
66
|
|
67
|
-
desc
|
67
|
+
desc "crop_images [config_name]", "crops images to the same height"
|
68
68
|
def crop_images(config_name)
|
69
69
|
crop = Wraith::CropImages.new(config_name)
|
70
70
|
crop.crop_images
|
71
71
|
end
|
72
72
|
|
73
|
-
desc
|
73
|
+
desc "compare_images [config_name]", "compares images to generate diffs"
|
74
74
|
def compare_images(config_name)
|
75
75
|
compare = Wraith::CompareImages.new(config_name)
|
76
76
|
compare.compare_images
|
77
77
|
end
|
78
78
|
|
79
|
-
desc
|
79
|
+
desc "generate_thumbnails [config_name]", "create thumbnails for gallery"
|
80
80
|
def generate_thumbnails(config_name)
|
81
81
|
thumbs = Wraith::Thumbnails.new(config_name)
|
82
82
|
thumbs.generate_thumbnails
|
83
83
|
end
|
84
84
|
|
85
|
-
desc
|
85
|
+
desc "generate_gallery [config_name]", "create page for viewing images"
|
86
86
|
def generate_gallery(config_name, multi = false)
|
87
87
|
gallery = Wraith::GalleryGenerator.new(config_name, multi)
|
88
88
|
gallery.generate_gallery
|
89
89
|
end
|
90
90
|
|
91
|
-
desc
|
91
|
+
desc "capture [config_name]", "A full Wraith job"
|
92
92
|
def capture(config, multi = false)
|
93
93
|
reset_shots(config)
|
94
94
|
check_for_paths(config)
|
@@ -100,7 +100,7 @@ class Wraith::CLI < Thor
|
|
100
100
|
generate_gallery(config, multi)
|
101
101
|
end
|
102
102
|
|
103
|
-
desc
|
103
|
+
desc "multi_capture [filelist]", "A Batch of Wraith Jobs"
|
104
104
|
def multi_capture(filelist)
|
105
105
|
config_array = IO.readlines(filelist)
|
106
106
|
config_array.each do |config|
|
@@ -108,15 +108,16 @@ class Wraith::CLI < Thor
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
desc
|
111
|
+
desc "history [config_name]", "Setup a baseline set of shots"
|
112
112
|
def history(config)
|
113
113
|
reset_shots(config)
|
114
|
+
check_for_paths(config)
|
114
115
|
setup_folders(config)
|
115
116
|
save_images(config)
|
116
117
|
copy_old_shots(config)
|
117
118
|
end
|
118
119
|
|
119
|
-
desc
|
120
|
+
desc "latest [config_name]", "Capture new shots to compare with baseline"
|
120
121
|
def latest(config)
|
121
122
|
reset_shots(config)
|
122
123
|
restore_shots(config)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "wraith"
|
2
|
+
require "image_size"
|
3
|
+
require "open3"
|
4
|
+
require "parallel"
|
5
5
|
|
6
6
|
class Wraith::CompareImages
|
7
7
|
attr_reader :wraith
|
@@ -12,18 +12,18 @@ class Wraith::CompareImages
|
|
12
12
|
|
13
13
|
def compare_images
|
14
14
|
files = Dir.glob("#{wraith.directory}/*/*.png").sort
|
15
|
-
Parallel.each(files.each_slice(2), in_processes
|
16
|
-
diff = base.gsub(/([a-z0-9]+).png$/,
|
17
|
-
info = base.gsub(/([a-z0-9]+).png$/,
|
15
|
+
Parallel.each(files.each_slice(2), :in_processes => Parallel.processor_count) do |base, compare|
|
16
|
+
diff = base.gsub(/([a-z0-9]+).png$/, "diff.png")
|
17
|
+
info = base.gsub(/([a-z0-9]+).png$/, "data.txt")
|
18
18
|
compare_task(base, compare, diff, info)
|
19
|
-
puts
|
19
|
+
puts "Saved diff"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def percentage(img_size, px_value, info)
|
24
24
|
pixel_count = (px_value / img_size) * 100
|
25
25
|
rounded = pixel_count.round(2)
|
26
|
-
File.open(info,
|
26
|
+
File.open(info, "w") { |file| file.write(rounded) }
|
27
27
|
end
|
28
28
|
|
29
29
|
def compare_task(base, compare, output, info)
|
@@ -33,7 +33,7 @@ class Wraith::CompareImages
|
|
33
33
|
img_size = ImageSize.path(output).size.inject(:*)
|
34
34
|
percentage(img_size, px_value, info)
|
35
35
|
rescue
|
36
|
-
File.open(info,
|
36
|
+
File.open(info, "w") { |file| file.write("invalid") } unless File.exist?(output)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/wraith/crop.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "wraith"
|
2
|
+
require "image_size"
|
3
|
+
require "parallel"
|
4
4
|
|
5
5
|
class Wraith::CropImages
|
6
6
|
attr_reader :wraith
|
@@ -12,8 +12,8 @@ class Wraith::CropImages
|
|
12
12
|
def crop_images
|
13
13
|
files = Dir.glob("#{wraith.directory}/*/*.png").sort
|
14
14
|
|
15
|
-
Parallel.each(files.each_slice(2), in_processes
|
16
|
-
puts
|
15
|
+
Parallel.each(files.each_slice(2), :in_processes => Parallel.processor_count) do |base, compare|
|
16
|
+
puts "cropping images"
|
17
17
|
|
18
18
|
width = image_dimensions(base)[0]
|
19
19
|
base_height = image_dimensions(base)[1]
|
@@ -36,6 +36,6 @@ class Wraith::CropImages
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def image_dimensions(image)
|
39
|
-
ImageSize.new(File.open(image,
|
39
|
+
ImageSize.new(File.open(image, "rb").read).size
|
40
40
|
end
|
41
41
|
end
|
data/lib/wraith/folder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "wraith"
|
2
2
|
|
3
3
|
class Wraith::FolderManager
|
4
4
|
attr_reader :wraith
|
@@ -38,7 +38,7 @@ class Wraith::FolderManager
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def restore_shots
|
41
|
-
puts
|
41
|
+
puts "restoring"
|
42
42
|
FileUtils.cp_r(Dir.glob("#{history_dir}/*"), dir)
|
43
43
|
end
|
44
44
|
|
@@ -46,17 +46,17 @@ class Wraith::FolderManager
|
|
46
46
|
spider_paths.each do |folder_label, path|
|
47
47
|
unless path
|
48
48
|
path = folder_label
|
49
|
-
folder_label = path.gsub(
|
49
|
+
folder_label = path.gsub("/", "__")
|
50
50
|
end
|
51
51
|
|
52
52
|
FileUtils.mkdir_p("#{dir}/thumbnails/#{folder_label}")
|
53
53
|
FileUtils.mkdir_p("#{dir}/#{folder_label}")
|
54
54
|
end
|
55
|
-
puts
|
55
|
+
puts "Creating Folders"
|
56
56
|
end
|
57
57
|
|
58
58
|
def tidy_shots_folder(dirs)
|
59
|
-
if wraith.mode ==
|
59
|
+
if wraith.mode == "diffs_only"
|
60
60
|
dirs.each do |folder_name, shot_info|
|
61
61
|
if shot_info.none? { |_k, v| v[:data] > 0 }
|
62
62
|
FileUtils.rm_rf("#{wraith.directory}/#{folder_name}")
|
data/lib/wraith/gallery.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "erb"
|
2
|
+
require "pp"
|
3
|
+
require "fileutils"
|
4
|
+
require "wraith/wraith"
|
5
5
|
|
6
6
|
class Wraith::GalleryGenerator
|
7
7
|
attr_reader :wraith
|
8
8
|
|
9
9
|
MATCH_FILENAME = /(\S+)_(\S+)\.\S+/
|
10
10
|
|
11
|
-
TEMPLATE_LOCATION = File.expand_path(
|
12
|
-
TEMPLATE_BY_DOMAIN_LOCATION = File.expand_path(
|
13
|
-
BOOTSTRAP_LOCATION = File.expand_path(
|
11
|
+
TEMPLATE_LOCATION = File.expand_path("gallery_template/gallery_template.erb", File.dirname(__FILE__))
|
12
|
+
TEMPLATE_BY_DOMAIN_LOCATION = File.expand_path("gallery_template/gallery_template.erb", File.dirname(__FILE__))
|
13
|
+
BOOTSTRAP_LOCATION = File.expand_path("gallery_template/bootstrap.min.css", File.dirname(__FILE__))
|
14
14
|
|
15
15
|
def initialize(config, multi)
|
16
16
|
@wraith = Wraith::Wraith.new(config)
|
@@ -22,10 +22,10 @@ class Wraith::GalleryGenerator
|
|
22
22
|
def parse_directories(dirname)
|
23
23
|
@dirs = {}
|
24
24
|
categories = Dir.foreach(dirname).select do |category|
|
25
|
-
if [
|
25
|
+
if [".", "..", "thumbnails"].include? category
|
26
26
|
# Ignore special dirs
|
27
27
|
false
|
28
|
-
elsif File.directory? "#{dirname}/#{category}"
|
28
|
+
elsif File.directory? "#{dirname}/#{category}"
|
29
29
|
# Ignore stray files
|
30
30
|
true
|
31
31
|
else
|
@@ -54,11 +54,11 @@ class Wraith::GalleryGenerator
|
|
54
54
|
def matcher(match, filename, dirname, category)
|
55
55
|
@size = match[1].to_i
|
56
56
|
@group = match[2]
|
57
|
-
@filepath = category +
|
57
|
+
@filepath = category + "/" + filename
|
58
58
|
@thumbnail = "thumbnails/#{category}/#{filename}"
|
59
59
|
|
60
60
|
if @dirs[category][@size].nil?
|
61
|
-
@dirs[category][@size] = { variants
|
61
|
+
@dirs[category][@size] = { :variants => [] }
|
62
62
|
end
|
63
63
|
|
64
64
|
size_dict = @dirs[category][@size]
|
@@ -68,9 +68,9 @@ class Wraith::GalleryGenerator
|
|
68
68
|
|
69
69
|
def data_group(group, size_dict, dirname, filepath)
|
70
70
|
case group
|
71
|
-
when
|
71
|
+
when "diff"
|
72
72
|
diff_check(size_dict, filepath)
|
73
|
-
when
|
73
|
+
when "data"
|
74
74
|
data_check(size_dict, dirname, filepath)
|
75
75
|
else
|
76
76
|
variant_check(size_dict, group)
|
@@ -79,16 +79,16 @@ class Wraith::GalleryGenerator
|
|
79
79
|
|
80
80
|
def variant_check(size_dict, group)
|
81
81
|
size_dict[:variants] << {
|
82
|
-
name
|
83
|
-
filename
|
84
|
-
thumb
|
82
|
+
:name => group,
|
83
|
+
:filename => @filepath,
|
84
|
+
:thumb => @thumbnail
|
85
85
|
}
|
86
86
|
size_dict[:variants].sort! { |a, b| a[:name] <=> b[:name] }
|
87
87
|
end
|
88
88
|
|
89
89
|
def diff_check(size_dict, filepath)
|
90
90
|
size_dict[:diff] = {
|
91
|
-
filename
|
91
|
+
:filename => filepath, :thumb => @thumbnail
|
92
92
|
}
|
93
93
|
end
|
94
94
|
|
@@ -109,23 +109,23 @@ class Wraith::GalleryGenerator
|
|
109
109
|
def generate_html(location, directories, template, destination, path)
|
110
110
|
template = File.read(template)
|
111
111
|
locals = {
|
112
|
-
location
|
113
|
-
directories
|
114
|
-
path
|
115
|
-
threshold
|
112
|
+
:location => location,
|
113
|
+
:directories => directories,
|
114
|
+
:path => path,
|
115
|
+
:threshold => wraith.threshold
|
116
116
|
}
|
117
117
|
html = ERB.new(template).result(ErbBinding.new(locals).get_binding)
|
118
|
-
File.open(destination,
|
118
|
+
File.open(destination, "w") do |outf|
|
119
119
|
outf.write(html)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
def generate_gallery(withPath =
|
123
|
+
def generate_gallery(withPath = "")
|
124
124
|
dest = "#{@location}/gallery.html"
|
125
125
|
directories = parse_directories(@location)
|
126
126
|
generate_html(@location, directories, TEMPLATE_BY_DOMAIN_LOCATION, dest, withPath)
|
127
127
|
FileUtils.cp(BOOTSTRAP_LOCATION, "#{@location}/bootstrap.min.css")
|
128
|
-
puts
|
128
|
+
puts "Gallery generated"
|
129
129
|
check_failed_shots
|
130
130
|
end
|
131
131
|
|
@@ -133,7 +133,7 @@ class Wraith::GalleryGenerator
|
|
133
133
|
if @mutli
|
134
134
|
return true
|
135
135
|
elsif @failed_shots == false
|
136
|
-
puts
|
136
|
+
puts "Failures detected"
|
137
137
|
exit 1
|
138
138
|
else
|
139
139
|
true
|
data/lib/wraith/save_images.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "wraith"
|
2
|
+
require "parallel"
|
3
3
|
|
4
4
|
class Wraith::SaveImages
|
5
|
-
attr_reader :wraith, :history
|
5
|
+
attr_reader :wraith, :history, :meta
|
6
6
|
|
7
7
|
def initialize(config, history = false)
|
8
8
|
@wraith = Wraith::Wraith.new(config)
|
9
9
|
@history = history
|
10
|
-
|
11
|
-
|
12
|
-
def directory
|
13
|
-
wraith.directory
|
10
|
+
@meta = SaveMetadata.new(@wraith, history)
|
14
11
|
end
|
15
12
|
|
16
13
|
def check_paths
|
@@ -22,33 +19,42 @@ class Wraith::SaveImages
|
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
22
|
+
def save_images
|
23
|
+
jobs = []
|
24
|
+
check_paths.each do |label, options|
|
25
|
+
settings = CaptureOptions.new(options, wraith)
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
wraith.widths.each do |width|
|
28
|
+
base_file_name = meta.file_names(width, label, meta.base_label)
|
29
|
+
compare_file_name = meta.file_names(width, label, meta.compare_label)
|
32
30
|
|
33
|
-
|
34
|
-
|
31
|
+
jobs << [label, settings.path, width, settings.base_url, base_file_name, settings.selector]
|
32
|
+
jobs << [label, settings.path, width, settings.compare_url, compare_file_name, settings.selector] unless settings.compare_url.nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
parallel_task(jobs)
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
-
wraith.
|
38
|
+
def capture_page_image(browser, url, width, file_name, selector)
|
39
|
+
puts `"#{browser}" "#{wraith.phantomjs_options}" "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}" "#{selector}"`
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
wraith.comp_domain + path unless wraith.comp_domain.nil?
|
43
|
-
end
|
42
|
+
private
|
44
43
|
|
45
|
-
def
|
46
|
-
|
44
|
+
def parallel_task(jobs)
|
45
|
+
Parallel.each(jobs, :in_threads => 8) do |_label, _path, width, url, filename, selector|
|
46
|
+
begin
|
47
|
+
attempt_image_capture(width, url, filename, selector, 5)
|
48
|
+
rescue => e
|
49
|
+
puts e
|
50
|
+
create_invalid_image(filename, width)
|
51
|
+
end
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
def attempt_image_capture(width, url, filename, selector, max_attempts)
|
50
56
|
max_attempts.times do |i|
|
51
|
-
capture_page_image engine, url, width, filename, selector
|
57
|
+
capture_page_image meta.engine, url, width, filename, selector
|
52
58
|
|
53
59
|
return if File.exist? filename
|
54
60
|
|
@@ -58,56 +64,88 @@ class Wraith::SaveImages
|
|
58
64
|
fail "Unable to capture image #{filename} after #{max_attempts} attempt(s)"
|
59
65
|
end
|
60
66
|
|
67
|
+
def create_invalid_image(filename, width)
|
68
|
+
puts "Using fallback image instead"
|
69
|
+
invalid = File.expand_path("../../assets/invalid.jpg", File.dirname(__FILE__))
|
70
|
+
FileUtils.cp invalid, filename
|
71
|
+
|
72
|
+
set_image_width(filename, width)
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_image_width(image, width)
|
76
|
+
`convert #{image} -background none -extent #{width}x0 #{image}`
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class CaptureOptions
|
81
|
+
attr_reader :options, :wraith
|
82
|
+
|
83
|
+
def initialize(options, wraith)
|
84
|
+
@options = options
|
85
|
+
@wraith = wraith
|
86
|
+
end
|
87
|
+
|
88
|
+
def path
|
89
|
+
has_casper(options)
|
90
|
+
end
|
91
|
+
|
92
|
+
def selector
|
93
|
+
casper_selector(options)
|
94
|
+
end
|
95
|
+
|
96
|
+
def base_url
|
97
|
+
base_urls(path)
|
98
|
+
end
|
99
|
+
|
100
|
+
def compare_url
|
101
|
+
compare_urls(path)
|
102
|
+
end
|
103
|
+
|
104
|
+
def base_urls(path)
|
105
|
+
wraith.base_domain + path unless wraith.base_domain.nil?
|
106
|
+
end
|
107
|
+
|
108
|
+
def compare_urls(path)
|
109
|
+
wraith.comp_domain + path unless wraith.comp_domain.nil?
|
110
|
+
end
|
111
|
+
|
61
112
|
def has_casper(options)
|
62
|
-
options[
|
113
|
+
options["path"] ? options["path"] : options
|
63
114
|
end
|
64
115
|
|
65
116
|
def casper_selector(options)
|
66
|
-
options[
|
117
|
+
options["selector"] ? options["selector"] : " "
|
67
118
|
end
|
119
|
+
end
|
68
120
|
|
69
|
-
|
70
|
-
|
71
|
-
check_paths.each do |label, options|
|
72
|
-
path = has_casper(options)
|
73
|
-
selector = casper_selector(options)
|
74
|
-
|
75
|
-
base_url = base_urls(path)
|
76
|
-
compare_url = compare_urls(path)
|
121
|
+
class SaveMetadata
|
122
|
+
attr_reader :wraith, :history
|
77
123
|
|
78
|
-
|
79
|
-
|
80
|
-
|
124
|
+
def initialize(config, _history)
|
125
|
+
@wraith = config
|
126
|
+
end
|
81
127
|
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
parallel_task(jobs)
|
128
|
+
def history_label
|
129
|
+
history ? "_latest" : ""
|
87
130
|
end
|
88
131
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
attempt_image_capture(width, url, filename, selector, 5)
|
93
|
-
rescue => e
|
94
|
-
puts e
|
132
|
+
def engine_label
|
133
|
+
wraith.engine.key(wraith.engine)
|
134
|
+
end
|
95
135
|
|
96
|
-
|
97
|
-
|
98
|
-
|
136
|
+
def file_names(width, label, domain_label)
|
137
|
+
"#{wraith.directory}/#{label}/#{width}_#{engine_label}_#{domain_label}.png"
|
138
|
+
end
|
99
139
|
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
140
|
+
def base_label
|
141
|
+
"#{wraith.base_domain_label}#{history_label}"
|
104
142
|
end
|
105
143
|
|
106
|
-
def
|
107
|
-
|
144
|
+
def compare_label
|
145
|
+
"#{wraith.comp_domain_label}#{history_label}"
|
108
146
|
end
|
109
147
|
|
110
|
-
def
|
111
|
-
|
148
|
+
def engine
|
149
|
+
wraith.engine.each { |_label, browser| return browser }
|
112
150
|
end
|
113
151
|
end
|
data/lib/wraith/spider.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "wraith"
|
2
|
+
require "anemone"
|
3
|
+
require "nokogiri"
|
4
|
+
require "uri"
|
5
5
|
|
6
6
|
class Wraith::Spidering
|
7
7
|
def initialize(config)
|
@@ -11,10 +11,10 @@ class Wraith::Spidering
|
|
11
11
|
def check_for_paths
|
12
12
|
if @wraith.paths.nil?
|
13
13
|
unless @wraith.sitemap.nil?
|
14
|
-
puts
|
14
|
+
puts "no paths defined in config, loading paths from sitemap"
|
15
15
|
spider = Wraith::Sitemap.new(@wraith)
|
16
16
|
else
|
17
|
-
puts
|
17
|
+
puts "no paths defined in config, crawling from site root"
|
18
18
|
spider = Wraith::Crawler.new(@wraith)
|
19
19
|
end
|
20
20
|
spider.determine_paths
|
@@ -36,11 +36,11 @@ class Wraith::Spider
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def write_file
|
39
|
-
File.open(@wraith.spider_file,
|
39
|
+
File.open(@wraith.spider_file, "w+") { |file| file.write(@paths) }
|
40
40
|
end
|
41
41
|
|
42
42
|
def add_path(path)
|
43
|
-
@paths[path ==
|
43
|
+
@paths[path == "/" ? "home" : path.gsub("/", "__").chomp("__").downcase] = path.downcase
|
44
44
|
end
|
45
45
|
|
46
46
|
def spider
|
@@ -56,13 +56,13 @@ class Wraith::Crawler < Wraith::Spider
|
|
56
56
|
|
57
57
|
def spider
|
58
58
|
if File.exist?(@wraith.spider_file) && modified_since(@wraith.spider_file, @wraith.spider_days[0])
|
59
|
-
puts
|
59
|
+
puts "using existing spider file"
|
60
60
|
@paths = eval(File.read(@wraith.spider_file))
|
61
61
|
else
|
62
|
-
puts
|
62
|
+
puts "creating new spider file"
|
63
63
|
spider_list = []
|
64
64
|
Anemone.crawl(@wraith.base_domain) do |anemone|
|
65
|
-
anemone.skip_links_like(
|
65
|
+
anemone.skip_links_like(/\.(#{EXT.join('|')})$/)
|
66
66
|
# Add user specified skips
|
67
67
|
anemone.skip_links_like(@wraith.spider_skips)
|
68
68
|
anemone.on_every_page { |page| add_path(page.url.path) }
|
@@ -85,11 +85,11 @@ class Wraith::Sitemap < Wraith::Spider
|
|
85
85
|
sitemap = Nokogiri::XML(File.open(@wraith.sitemap))
|
86
86
|
end
|
87
87
|
urls = {}
|
88
|
-
sitemap.css(
|
88
|
+
sitemap.css("loc").each do |loc|
|
89
89
|
path = loc.content
|
90
90
|
# Allow use of either domain in the sitemap.xml
|
91
91
|
@wraith.domains.each do |_k, v|
|
92
|
-
path.sub!(v,
|
92
|
+
path.sub!(v, "")
|
93
93
|
end
|
94
94
|
if @wraith.spider_skips.nil? || @wraith.spider_skips.none? { |regex| regex.match(path) }
|
95
95
|
add_path(path)
|
data/lib/wraith/thumbnails.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "wraith"
|
2
|
+
require "parallel"
|
3
|
+
require "fileutils"
|
4
4
|
|
5
5
|
class Wraith::Thumbnails
|
6
6
|
attr_reader :wraith
|
@@ -10,11 +10,11 @@ class Wraith::Thumbnails
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def generate_thumbnails
|
13
|
-
puts
|
13
|
+
puts "Generating thumbnails"
|
14
14
|
|
15
15
|
files = Dir.glob("#{wraith.directory}/*/*.png")
|
16
16
|
|
17
|
-
Parallel.each(files, in_processes
|
17
|
+
Parallel.each(files, :in_processes => Parallel.processor_count) do |filename|
|
18
18
|
new_name = filename.gsub(/^#{wraith.directory}/, "#{wraith.directory}/thumbnails")
|
19
19
|
thumbnail_image(filename, new_name)
|
20
20
|
end
|
data/lib/wraith/version.rb
CHANGED
data/lib/wraith/wraith.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
require
|
1
|
+
require "yaml"
|
2
2
|
|
3
3
|
class Wraith::Wraith
|
4
4
|
attr_accessor :config
|
5
5
|
|
6
6
|
def initialize(config_name)
|
7
|
-
if File.exist?(config_name) && File.extname(config_name) ==
|
7
|
+
if File.exist?(config_name) && File.extname(config_name) == ".yaml"
|
8
8
|
@config = YAML.load(File.open(config_name))
|
9
9
|
else
|
10
10
|
@config = YAML.load(File.open("configs/#{config_name}.yaml"))
|
11
11
|
end
|
12
12
|
rescue
|
13
|
-
puts
|
13
|
+
puts "unable to find config"
|
14
14
|
exit 1
|
15
15
|
end
|
16
16
|
|
17
17
|
def directory
|
18
18
|
# Legacy support for those using array configs
|
19
|
-
@config[
|
19
|
+
@config["directory"].is_a?(Array) ? @config["directory"].first : @config["directory"]
|
20
20
|
end
|
21
21
|
|
22
22
|
def history_dir
|
23
|
-
@config[
|
23
|
+
@config["history_dir"]
|
24
24
|
end
|
25
25
|
|
26
26
|
def snap_file
|
27
|
-
@config[
|
27
|
+
@config["snap_file"] ? @config["snap_file"] : File.expand_path("lib/wraith/javascript/snap.js")
|
28
28
|
end
|
29
29
|
|
30
30
|
def widths
|
31
|
-
@config[
|
31
|
+
@config["screen_widths"]
|
32
32
|
end
|
33
33
|
|
34
34
|
def domains
|
35
|
-
@config[
|
35
|
+
@config["domains"]
|
36
36
|
end
|
37
37
|
|
38
38
|
def base_domain
|
@@ -52,46 +52,46 @@ class Wraith::Wraith
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def spider_file
|
55
|
-
@config[
|
55
|
+
@config["spider_file"] ? @config["spider_file"] : "spider.txt"
|
56
56
|
end
|
57
57
|
|
58
58
|
def spider_days
|
59
|
-
@config[
|
59
|
+
@config["spider_days"]
|
60
60
|
end
|
61
61
|
|
62
62
|
def sitemap
|
63
|
-
@config[
|
63
|
+
@config["sitemap"]
|
64
64
|
end
|
65
65
|
|
66
66
|
def spider_skips
|
67
|
-
@config[
|
67
|
+
@config["spider_skips"]
|
68
68
|
end
|
69
69
|
|
70
70
|
def paths
|
71
|
-
@config[
|
71
|
+
@config["paths"]
|
72
72
|
end
|
73
73
|
|
74
74
|
def engine
|
75
|
-
@config[
|
75
|
+
@config["browser"]
|
76
76
|
end
|
77
77
|
|
78
78
|
def fuzz
|
79
|
-
@config[
|
79
|
+
@config["fuzz"]
|
80
80
|
end
|
81
81
|
|
82
82
|
def mode
|
83
|
-
if %w(diffs_only diffs_first alphanumeric).include?(@config[
|
84
|
-
@config[
|
83
|
+
if %w(diffs_only diffs_first alphanumeric).include?(@config["mode"])
|
84
|
+
@config["mode"]
|
85
85
|
else
|
86
|
-
|
86
|
+
"alphanumeric"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
def threshold
|
91
|
-
@config[
|
91
|
+
@config["threshold"] ? @config["threshold"] : 0
|
92
92
|
end
|
93
93
|
|
94
94
|
def phantomjs_options
|
95
|
-
@config[
|
95
|
+
@config["phantomjs_options"]
|
96
96
|
end
|
97
97
|
end
|
data/spec/wraith_spec.rb
CHANGED
@@ -1,68 +1,116 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rspec"
|
2
|
+
require "image_size"
|
3
|
+
require "./lib/wraith/cli"
|
4
4
|
|
5
5
|
describe Wraith do
|
6
|
-
|
7
|
-
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:data_txt) { 'shots/test/test.txt' }
|
15
|
-
let(:selector) { '' }
|
6
|
+
let(:config_name) { "test_config" }
|
7
|
+
let(:test_url1) { "http://www.bbc.co.uk/russian" }
|
8
|
+
let(:test_url2) { "http://www.bbc.co.uk/russian" }
|
9
|
+
let(:test_image1) { "shots/test/test1.png" }
|
10
|
+
let(:test_image2) { "shots/test/test2.png" }
|
11
|
+
let(:diff_image) { "shots/test/test_diff.png" }
|
12
|
+
let(:data_txt) { "shots/test/test.txt" }
|
13
|
+
let(:selector) { "" }
|
16
14
|
let(:saving) { Wraith::SaveImages.new(config_name) }
|
15
|
+
let(:wraith) { Wraith::Wraith.new(config_name) }
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
before(:each) do
|
18
|
+
Wraith::FolderManager.new(config_name).clear_shots_folder
|
19
|
+
Dir.mkdir("shots/test")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
+
describe "Config" do
|
23
|
+
it "returns a Wraith class" do
|
24
|
+
expect(wraith).is_a? Wraith::Wraith
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
it "when config is loaded" do
|
28
|
+
expect(wraith).to respond_to :config
|
29
|
+
end
|
30
|
+
|
31
|
+
it "contains shot options" do
|
32
|
+
expect(wraith.config).to include "directory" => "shots"
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
|
-
context
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
context "When creating a wraith worker" do
|
37
|
+
it "should have 7 config keys" do
|
38
|
+
expect(wraith.config.keys.size).to be 7
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have widths" do
|
42
|
+
expect(wraith.widths).to eq [320, 600, 1280]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "include base domain" do
|
46
|
+
expect(wraith.base_domain).to eq "http://www.bbc.co.uk/russian"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "include compare domain" do
|
50
|
+
expect(wraith.comp_domain).to eq "http://www.bbc.co.uk/russian"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "include base label" do
|
54
|
+
expect(wraith.base_domain_label).to eq "english"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "include compare label" do
|
58
|
+
expect(wraith.comp_domain_label).to eq "russian"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "include compare label" do
|
62
|
+
expect(wraith.paths).to eq("home" => "/", "uk_index" => "/uk")
|
38
63
|
end
|
39
|
-
When(:image_size) { ImageSize.path(test_image1).size }
|
40
|
-
Then { image_size[0] == 320 }
|
41
64
|
end
|
42
65
|
|
43
|
-
|
44
|
-
|
66
|
+
describe "When capturing an image" do
|
67
|
+
let(:image_size) { ImageSize.path(test_image1).size }
|
68
|
+
|
69
|
+
it "saves image" do
|
45
70
|
wraith.engine.each do |_type, engine|
|
46
71
|
saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
|
47
|
-
saving.capture_page_image(engine, test_url2, 320, test_image2, selector)
|
48
72
|
end
|
49
|
-
|
50
|
-
|
51
|
-
ImageSize.path(diff_image).size
|
73
|
+
|
74
|
+
expect(image_size[0]).to eq 320
|
52
75
|
end
|
53
|
-
Then { diff_image_size[0] == 320 }
|
54
76
|
end
|
55
77
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
78
|
+
describe "When comparing images" do
|
79
|
+
it "should compare" do
|
80
|
+
create_diff_image
|
81
|
+
crop_images
|
82
|
+
compare_images
|
83
|
+
|
84
|
+
diff = ImageSize.path(diff_image).size
|
85
|
+
|
86
|
+
expect(diff[0]).to eq 320
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "When generating tumbnails" do
|
91
|
+
it "produce thumbnails" do
|
92
|
+
create_diff_image
|
63
93
|
Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
|
64
94
|
Wraith::Thumbnails.new(config_name).generate_thumbnails
|
95
|
+
|
96
|
+
expect(File).to exist("shots/thumbnails/test/test1.png")
|
97
|
+
expect(File).to exist("shots/thumbnails/test/test2.png")
|
98
|
+
expect(File).to exist("shots/thumbnails/test/test_diff.png")
|
65
99
|
end
|
66
|
-
Then { File.exist?('shots/thumbnails/test/test1.png') && File.exist?('shots/thumbnails/test/test2.png') && File.exist?('shots/thumbnails/test/test_diff.png') }
|
67
100
|
end
|
68
101
|
end
|
102
|
+
|
103
|
+
def create_diff_image
|
104
|
+
wraith.engine.each do |_type, engine|
|
105
|
+
saving.capture_page_image(engine, test_url1, 320, test_image1, selector)
|
106
|
+
saving.capture_page_image(engine, test_url2, 320, test_image2, selector)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def crop_images
|
111
|
+
Wraith::CropImages.new(config_name).crop_images
|
112
|
+
end
|
113
|
+
|
114
|
+
def compare_images
|
115
|
+
Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
|
116
|
+
end
|
@@ -11,7 +11,12 @@ var selector = casper.cli.get(3);
|
|
11
11
|
casper.start(url, function() {
|
12
12
|
this.viewport(view_port_width, 1500).then(function(){
|
13
13
|
this.wait(2000, function() {
|
14
|
-
|
14
|
+
if (selector == undefined) {
|
15
|
+
this.capture(image_name);
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
this.captureSelector(image_name, selector);
|
19
|
+
}
|
15
20
|
console.log('Snapping ' + url + ' at width ' + view_port_width);
|
16
21
|
});
|
17
22
|
});
|
data/wraith.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_development_dependency 'pry'
|
22
|
-
spec.add_development_dependency 'rspec
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
23
|
|
24
24
|
spec.add_runtime_dependency 'rake'
|
25
25
|
spec.add_runtime_dependency 'image_size'
|
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.3.
|
4
|
+
version: 2.3.3
|
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: 2015-
|
12
|
+
date: 2015-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name: rspec
|
29
|
+
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - '>='
|
@@ -177,6 +177,7 @@ extra_rdoc_files: []
|
|
177
177
|
files:
|
178
178
|
- .gemset
|
179
179
|
- .gitignore
|
180
|
+
- .rubocop.yml
|
180
181
|
- .ruby-version
|
181
182
|
- .travis.yml
|
182
183
|
- Dockerfile
|