wraith 2.8.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wraith/gallery.rb +9 -2
- data/lib/wraith/javascript/_helper.js +45 -0
- data/lib/wraith/javascript/_phantom__common.js +112 -0
- data/lib/wraith/javascript/casper.js +81 -0
- data/{templates → lib/wraith}/javascript/phantom--nojs.js +0 -0
- data/{templates → lib/wraith}/javascript/phantom.js +0 -0
- data/lib/wraith/save_images.rb +45 -17
- data/lib/wraith/version.rb +1 -1
- data/lib/wraith/wraith.rb +39 -11
- data/spec/{helpers.rb → _helpers.rb} +5 -4
- data/spec/before_capture_spec.rb +81 -0
- data/spec/config_spec.rb +139 -0
- data/spec/configs/test_config--casper.yaml +2 -2
- data/spec/configs/test_config--phantom.yaml +3 -3
- data/spec/gallery_spec.rb +38 -0
- data/{templates/javascript/casper.js → spec/js/custom_snap_file.js} +5 -1
- data/spec/resize_reload_spec.rb +55 -0
- data/spec/save_images_spec.rb +54 -0
- data/templates/configs/component.yaml +4 -7
- data/templates/configs/multiple_domains.yaml +2 -8
- data/templates/configs/spider.yaml +13 -19
- data/templates/javascript/beforeCapture--casper_example.js +10 -3
- data/templates/javascript/beforeCapture--phantom_example.js +29 -2
- metadata +51 -42
- data/spec/wraith_spec.rb +0 -209
- data/templates/javascript/README.md +0 -5
- data/templates/javascript/_getDimensions.js +0 -7
- data/templates/javascript/_phantom__common.js +0 -122
@@ -1,8 +1,9 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "./lib/wraith/cli"
|
3
|
+
|
1
4
|
def create_diff_image
|
2
|
-
wraith.engine
|
3
|
-
|
4
|
-
saving.capture_page_image(engine, test_url2, 320, test_image2, selector, 'false', 'false')
|
5
|
-
end
|
5
|
+
saving.capture_page_image(wraith.engine, test_url1, 320, test_image1, selector, 'false', 'false')
|
6
|
+
saving.capture_page_image(wraith.engine, test_url2, 320, test_image2, selector, 'false', 'false')
|
6
7
|
end
|
7
8
|
|
8
9
|
def crop_images
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "_helpers"
|
2
|
+
|
3
|
+
describe Wraith do
|
4
|
+
let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--casper.yaml" }
|
5
|
+
let(:test_url1) { "http://www.bbc.com/afrique" }
|
6
|
+
let(:diff_image) { "shots/test/test_diff.png" }
|
7
|
+
let(:data_txt) { "shots/test/test.txt" }
|
8
|
+
let(:saving) { Wraith::SaveImages.new(config_name) }
|
9
|
+
let(:wraith) { Wraith::Wraith.new(config_name) }
|
10
|
+
let(:selector) { "body" }
|
11
|
+
let(:before_suite_js) { "spec/js/global.js" }
|
12
|
+
let(:before_capture_js) { "spec/js/path.js" }
|
13
|
+
|
14
|
+
describe "When hooking into beforeCapture (CasperJS)" do
|
15
|
+
|
16
|
+
it "Executes the global JS before capturing" do
|
17
|
+
run_js_then_capture(
|
18
|
+
global_js: before_suite_js,
|
19
|
+
path_js: 'false',
|
20
|
+
output_should_look_like: 'spec/base/global.png',
|
21
|
+
engine: 'casperjs'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "Executes the path-level JS before capturing" do
|
26
|
+
run_js_then_capture(
|
27
|
+
global_js: 'false',
|
28
|
+
path_js: before_capture_js,
|
29
|
+
output_should_look_like: 'spec/base/path.png',
|
30
|
+
engine: 'casperjs'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "Executes the global JS before the path-level JS" do
|
35
|
+
run_js_then_capture(
|
36
|
+
global_js: before_suite_js,
|
37
|
+
path_js: before_capture_js,
|
38
|
+
output_should_look_like: 'spec/base/path.png',
|
39
|
+
engine: 'casperjs'
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @TODO - uncomment and figure out why broken
|
45
|
+
# describe "When hooking into beforeCapture (PhantomJS)" do
|
46
|
+
# let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
|
47
|
+
# let(:saving) { Wraith::SaveImages.new(config_name) }
|
48
|
+
# let(:wraith) { Wraith::Wraith.new(config_name) }
|
49
|
+
# let(:selector) { "body" }
|
50
|
+
# let(:before_suite_js) { "../../spec/js/global.js" }
|
51
|
+
# let(:before_capture_js) { "../../spec/js/path.js" }
|
52
|
+
|
53
|
+
# it "Executes the global JS before capturing" do
|
54
|
+
# run_js_then_capture(
|
55
|
+
# global_js: before_suite_js,
|
56
|
+
# path_js: 'false',
|
57
|
+
# output_should_look_like: 'spec/base/global.png',
|
58
|
+
# engine: 'phantomjs'
|
59
|
+
# )
|
60
|
+
# end
|
61
|
+
|
62
|
+
# it "Executes the path-level JS before capturing" do
|
63
|
+
# run_js_then_capture(
|
64
|
+
# global_js: 'false',
|
65
|
+
# path_js: before_capture_js,
|
66
|
+
# output_should_look_like: 'spec/base/path.png',
|
67
|
+
# engine: 'phantomjs'
|
68
|
+
# )
|
69
|
+
# end
|
70
|
+
|
71
|
+
# it "Executes the global JS before the path-level JS" do
|
72
|
+
# run_js_then_capture(
|
73
|
+
# global_js: before_suite_js,
|
74
|
+
# path_js: before_capture_js,
|
75
|
+
# output_should_look_like: 'spec/base/path.png',
|
76
|
+
# engine: 'phantomjs'
|
77
|
+
# )
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
|
81
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require "_helpers"
|
2
|
+
|
3
|
+
describe "wraith config" do
|
4
|
+
|
5
|
+
let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
|
6
|
+
let(:wraith) { Wraith::Wraith.new(config_name) }
|
7
|
+
|
8
|
+
describe "Config" do
|
9
|
+
it "returns a Wraith class" do
|
10
|
+
expect(wraith).is_a? Wraith::Wraith
|
11
|
+
end
|
12
|
+
|
13
|
+
it "when config is loaded" do
|
14
|
+
expect(wraith).to respond_to :config
|
15
|
+
end
|
16
|
+
|
17
|
+
it "contains shot options" do
|
18
|
+
expect(wraith.config).to include "directory" => "shots"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "When creating a wraith worker" do
|
23
|
+
|
24
|
+
it "should have a browser engine defined" do
|
25
|
+
expect(wraith.engine).to be_a String
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a directory defined" do
|
29
|
+
expect(wraith.directory).to be_a String
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have domains defined" do
|
33
|
+
expect(wraith.domains).to be_a Hash
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have screen widths defined" do
|
37
|
+
expect(wraith.widths).to be_a Array
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have paths defined" do
|
41
|
+
expect(wraith.paths).to be_a Hash
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have fuzz defined" do
|
45
|
+
expect(wraith.fuzz).to be_a String
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have widths" do
|
49
|
+
expect(wraith.widths).to eq [320, 600, 1280]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "include base domain" do
|
53
|
+
expect(wraith.base_domain).to eq "http://www.bbc.com/afrique"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "include compare domain" do
|
57
|
+
expect(wraith.comp_domain).to eq "http://www.bbc.com/russian"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "include base label" do
|
61
|
+
expect(wraith.base_domain_label).to eq "afrique"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "include compare label" do
|
65
|
+
expect(wraith.comp_domain_label).to eq "russian"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "include compare label" do
|
69
|
+
expect(wraith.paths).to eq("home" => "/", "uk_index" => "/uk")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "different ways of initialising browser engine" do
|
74
|
+
|
75
|
+
it "should let us directly specify the engine" do
|
76
|
+
config = YAML.load 'browser: phantomjs'
|
77
|
+
wraith = Wraith::Wraith.new(config, true)
|
78
|
+
|
79
|
+
expect(wraith.engine).to eq 'phantomjs'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should be backwards compatible with the old way" do
|
83
|
+
config = YAML.load '
|
84
|
+
browser:
|
85
|
+
phantomjs: "casperjs"
|
86
|
+
'
|
87
|
+
wraith = Wraith::Wraith.new(config, true)
|
88
|
+
expect(wraith.engine).to eq 'casperjs'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "different ways of determining the snap file" do
|
93
|
+
|
94
|
+
it "should calculate the snap file from the engine" do
|
95
|
+
config = YAML.load 'browser: phantomjs'
|
96
|
+
wraith = Wraith::Wraith.new(config, true)
|
97
|
+
expect(wraith.snap_file).to include 'lib/wraith/javascript/phantom.js'
|
98
|
+
|
99
|
+
config = YAML.load 'browser: casperjs'
|
100
|
+
wraith = Wraith::Wraith.new(config, true)
|
101
|
+
expect(wraith.snap_file).to include 'lib/wraith/javascript/casper.js'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should calculate the snap file in a backwards-compatible way" do
|
105
|
+
config = YAML.load '
|
106
|
+
browser:
|
107
|
+
phantomjs: "casperjs"
|
108
|
+
'
|
109
|
+
wraith = Wraith::Wraith.new(config, true)
|
110
|
+
expect(wraith.snap_file).to include 'lib/wraith/javascript/casper.js'
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should allow users to specify their own snap file" do
|
114
|
+
config = YAML.load '
|
115
|
+
browser: casperjs
|
116
|
+
snap_file: path/to/snap.js
|
117
|
+
'
|
118
|
+
wraith = Wraith::Wraith.new(config, true)
|
119
|
+
expect(wraith.snap_file).to eq 'path/to/snap.js'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "different modes of efficiency (resize or reload)" do
|
124
|
+
|
125
|
+
it "should trigger efficient mode if resize was specified" do
|
126
|
+
config = YAML.load 'resize_or_reload: "resize"'
|
127
|
+
wraith = Wraith::Wraith.new(config, true)
|
128
|
+
expect(wraith.resize)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should fall back to slow mode if reload was specified" do
|
132
|
+
config = YAML.load 'resize_or_reload: "reload"'
|
133
|
+
wraith = Wraith::Wraith.new(config, true)
|
134
|
+
expect(wraith.resize).to eq false
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -8,8 +8,8 @@ browser:
|
|
8
8
|
phantomjs: "casperjs"
|
9
9
|
# slimerjs: "slimerjs"
|
10
10
|
|
11
|
-
#
|
12
|
-
snap_file: "
|
11
|
+
#overriding the snap file
|
12
|
+
snap_file: "spec/js/custom_snap_file.js"
|
13
13
|
|
14
14
|
# Type the name of the directory that shots will be stored in
|
15
15
|
directory: 'shots'
|
@@ -6,10 +6,10 @@
|
|
6
6
|
#Headless browser option
|
7
7
|
browser:
|
8
8
|
phantomjs: "phantomjs"
|
9
|
-
# slimerjs: "slimerjs"
|
10
9
|
|
11
|
-
#
|
12
|
-
|
10
|
+
# we've deliberately left out the snap_file
|
11
|
+
|
12
|
+
resize_or_reload: resize
|
13
13
|
|
14
14
|
# Type the name of the directory that shots will be stored in
|
15
15
|
directory: 'shots'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "_helpers"
|
2
|
+
|
3
|
+
describe Wraith do
|
4
|
+
let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
|
5
|
+
let(:gallery) { Wraith::GalleryGenerator.new(config_name, false) }
|
6
|
+
|
7
|
+
describe "When generating gallery" do
|
8
|
+
|
9
|
+
it "should not break when there is a `-` in the filename" do
|
10
|
+
dirs = gallery.parse_directories 'spec/thumbnails'
|
11
|
+
|
12
|
+
images = [
|
13
|
+
{
|
14
|
+
:filename => 'home/test_image-afrique.png',
|
15
|
+
:thumb => 'thumbnails/home/test_image-afrique.png'
|
16
|
+
},
|
17
|
+
{
|
18
|
+
:filename => 'home/test_image-russian.png',
|
19
|
+
:thumb => 'thumbnails/home/test_image-russian.png'
|
20
|
+
}
|
21
|
+
]
|
22
|
+
|
23
|
+
dirs['home'][0][:variants].each_with_index do |image, i|
|
24
|
+
expect(image[:filename]).to eq images[i][:filename]
|
25
|
+
expect(image[:thumb]).to eq images[i][:thumb]
|
26
|
+
end
|
27
|
+
|
28
|
+
diff = {
|
29
|
+
:filename => 'home/test_image-diff.png',
|
30
|
+
:thumb => 'thumbnails/home/test_image-diff.png'
|
31
|
+
}
|
32
|
+
|
33
|
+
expect(dirs['home'][0][:diff][:filename]).to eq 'home/test_image-diff.png'
|
34
|
+
expect(dirs['home'][0][:diff][:thumb]).to eq 'thumbnails/home/test_image-diff.png'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -4,7 +4,11 @@ var system = require('system'),
|
|
4
4
|
|
5
5
|
// command line arguments
|
6
6
|
var url = casper.cli.get(0),
|
7
|
-
|
7
|
+
dimensions_tmp = /(\d*)x?((\d*))?/i.exec(casper.cli.get(1));
|
8
|
+
dimensions = {
|
9
|
+
'viewportWidth': parseInt(dimensions_tmp[1]),
|
10
|
+
'viewportHeight': parseInt(dimensions_tmp[2] || 1500)
|
11
|
+
},
|
8
12
|
image_name = casper.cli.get(2),
|
9
13
|
selector = casper.cli.get(3),
|
10
14
|
globalBeforeCaptureJS = casper.cli.get(4),
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "_helpers"
|
2
|
+
|
3
|
+
describe "wraith config" do
|
4
|
+
|
5
|
+
let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
|
6
|
+
let(:saving) { Wraith::SaveImages.new(config_name) }
|
7
|
+
|
8
|
+
describe "saving images" do
|
9
|
+
|
10
|
+
it "should pass the width plainly to the CLI when running in inefficient mode" do
|
11
|
+
prepared_width = saving.prepare_widths_for_cli 432
|
12
|
+
expect(prepared_width).to eq 432
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should pass an array of widths to CLI when running in efficient mode" do
|
16
|
+
prepared_width = saving.prepare_widths_for_cli [432, 21, 100]
|
17
|
+
expect(prepared_width).to eq "'432','21','100'"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create fewer jobs when in efficient mode" do
|
21
|
+
base_config = '
|
22
|
+
domains:
|
23
|
+
test: http://www.bbc.com
|
24
|
+
paths:
|
25
|
+
test: /mypage
|
26
|
+
screen_widths:
|
27
|
+
- 320
|
28
|
+
- 464
|
29
|
+
- 624
|
30
|
+
'
|
31
|
+
efficient_config = YAML.load(base_config + "
|
32
|
+
resize_or_reload: resize
|
33
|
+
")
|
34
|
+
efficient_saving = Wraith::SaveImages.new(efficient_config, false, true)
|
35
|
+
inefficient_config = YAML.load(base_config + "
|
36
|
+
resize_or_reload: reload
|
37
|
+
")
|
38
|
+
inefficient_saving = Wraith::SaveImages.new(inefficient_config, false, true)
|
39
|
+
|
40
|
+
efficient_jobs = efficient_saving.define_jobs
|
41
|
+
inefficient_jobs = inefficient_saving.define_jobs
|
42
|
+
|
43
|
+
expect(efficient_jobs.length).to be 1
|
44
|
+
expect(inefficient_jobs.length).to be 3 # 1 for each screen width
|
45
|
+
|
46
|
+
# [["test", "/mypage", "'320','464','624'", "http://www.bbc.com/mypage", "/test/MULTI__test.png", " ", "false", "false"]]
|
47
|
+
expect(efficient_jobs[0][2]).to eq "'320','464','624'"
|
48
|
+
|
49
|
+
# [["test", "/mypage", 320, "http://www.bbc.com/mypage", "/test/320__test.png", " ", "false", "false"], ["test", "/mypage", 464, "http://www.bbc.com/mypage", "/test/464__test.png", " ", "false", "false"], ["test", "/mypage", 624, "http://www.bbc.com/mypage", "/test/624__test.png", " ", "false", "false"]]
|
50
|
+
expect(inefficient_jobs[0][2]).to eq 320
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "_helpers"
|
2
|
+
require "image_size"
|
3
|
+
|
4
|
+
describe Wraith do
|
5
|
+
let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--phantom.yaml" }
|
6
|
+
let(:test_url1) { "http://www.bbc.com/afrique" }
|
7
|
+
let(:test_url2) { "http://www.bbc.com/russian" }
|
8
|
+
let(:test_image1) { "shots/test/test1.png" }
|
9
|
+
let(:test_image2) { "shots/test/test(2).png" }
|
10
|
+
let(:diff_image) { "shots/test/test_diff.png" }
|
11
|
+
let(:data_txt) { "shots/test/test.txt" }
|
12
|
+
let(:selector) { "" }
|
13
|
+
let(:saving) { Wraith::SaveImages.new(config_name) }
|
14
|
+
let(:wraith) { Wraith::Wraith.new(config_name) }
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
Wraith::FolderManager.new(config_name).clear_shots_folder
|
18
|
+
Dir.mkdir("shots/test")
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "When capturing an image" do
|
22
|
+
let(:image_size) { ImageSize.path(test_image1).size }
|
23
|
+
|
24
|
+
it "saves image" do
|
25
|
+
saving.capture_page_image(wraith.engine, test_url1, 320, test_image1, selector, 'false', 'false')
|
26
|
+
expect(image_size[0]).to eq 320
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "When comparing images" do
|
31
|
+
it "should compare" do
|
32
|
+
create_diff_image
|
33
|
+
crop_images
|
34
|
+
compare_images
|
35
|
+
|
36
|
+
diff = ImageSize.path(diff_image).size
|
37
|
+
|
38
|
+
expect(diff[0]).to eq 320
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "When generating thumbnails" do
|
43
|
+
it "produce thumbnails" do
|
44
|
+
create_diff_image
|
45
|
+
crop_images
|
46
|
+
Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
|
47
|
+
Wraith::Thumbnails.new(config_name).generate_thumbnails
|
48
|
+
|
49
|
+
expect(File).to exist("shots/thumbnails/test/test1.png")
|
50
|
+
expect(File).to exist("shots/thumbnails/test/test(2).png")
|
51
|
+
expect(File).to exist("shots/thumbnails/test/test_diff.png")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -34,14 +34,11 @@ screen_widths:
|
|
34
34
|
- 1024
|
35
35
|
- 1280
|
36
36
|
|
37
|
-
#
|
38
|
-
|
39
|
-
phantomjs: "casperjs" # variant of PhantomJS that allows screenshots by element selector
|
40
|
-
#phantomjs: "phantomjs" # PhantomJS, built on top of Webkit and JavascriptCore (like Safari)
|
41
|
-
#slimerjs: "slimerjs" # SlimerJS, built on top of Gecko and SpiderMonkey (like Firefox)
|
37
|
+
# resize to each screen width, or reload at each screen width. (The former is more efficient).
|
38
|
+
resize_or_reload: 'resize'
|
42
39
|
|
43
|
-
# the
|
44
|
-
|
40
|
+
# the engine to run Wraith with.
|
41
|
+
browser: "casperjs"
|
45
42
|
|
46
43
|
# the directory that your base screenshots will be stored in
|
47
44
|
history_dir: 'shots_base'
|