capybara-paparazzi 0.0.3 → 0.0.4
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/README.md +45 -4
- data/lib/capybara/paparazzi/shooter.rb +31 -11
- data/lib/capybara/paparazzi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fff1e15a40ceebe2d581d6132e1b9d4b1ad4c101
|
4
|
+
data.tar.gz: fec0f04b14a119d04e71c7c2603131e5ff34adbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd6528b34e4230b5000be4013d167b80eb2ef60036b38a4e2a549e06c50833a2b289ba0bcde9ac9e0619cb4ad8d1cd770df1b34f0c14f4f6c1da80efef05d4b6
|
7
|
+
data.tar.gz: a6656aea3c0fc0084c50d32e9954ab94ec9e4bb20aba510febbc3bc6bb355180a60ee3ec7bf0ef52ee7aa31c9db598fb863d62459d8a9cb8ce42dcb6d72f8884
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Capybara::Paparazzi hooks into Capybara's feature tests and takes
|
|
13
13
|
pictures at significant user actions (like visiting a page, clicking
|
14
14
|
buttons, etc.). It relies on a driver that supports saving screenshots
|
15
15
|
and executing javascript, and was originally built with Poltergeist in
|
16
|
-
mind.
|
16
|
+
mind (due to its headless nature).
|
17
17
|
|
18
18
|
A few driving principles of Capybara::Paparazzi:
|
19
19
|
|
@@ -91,6 +91,11 @@ Capybara::Paparazzi.config do |config|
|
|
91
91
|
config.js_var_style.merge!(color: 'red', fontWeight: 'bold')
|
92
92
|
config.screenshot_sizes = [ config.screenshot_sizes.first, (config.screenshot_sizes.last + [ :EXTRA_DATA ]) ]
|
93
93
|
config.file_dir = '../screenshots'
|
94
|
+
# config.make_fewer_directories = true
|
95
|
+
# config.make_shorter_filenames = true
|
96
|
+
config.path_and_suffix_generator = ->(shooter, url) {
|
97
|
+
shooter.path_and_suffix_for_url(url).collect{|p| p.split('/').last }
|
98
|
+
}
|
94
99
|
# config.js_setup_script = ->(shooter){ ... }
|
95
100
|
config.js_resize_script = ->(shooter, height) {
|
96
101
|
"#{shooter.js_var_name}.style.height = '#{height}px'; MY_FOLD_DIV.textContent = #{shooter.screenshot_size.inspect.to_json}; MY_FOLD_DIV.style.fontSize = '#{height/4}px';"
|
@@ -160,6 +165,30 @@ you can change the screenshot sizes with
|
|
160
165
|
The first 2 values in the array are width and height, but the whole array
|
161
166
|
is made available for use in customized configuration scripts.
|
162
167
|
|
168
|
+
### Filenames
|
169
|
+
|
170
|
+
By default, a new directory is created to contain the screenshots for
|
171
|
+
each distinct URL. There are a few ways to change this if it's not to
|
172
|
+
your liking:
|
173
|
+
|
174
|
+
1. Use `config.make_fewer_directories = true`, which will skip the last
|
175
|
+
directory level and put screenshots for multiple pages in the same
|
176
|
+
directory.
|
177
|
+
|
178
|
+
2. Use `config.make_shorter_filenames = true`, which causes the basenames
|
179
|
+
of the files not to include a representation of the full path
|
180
|
+
(the full path in the basename makes it easier to understand when
|
181
|
+
copied/moved outside of the screenshots directory tree).
|
182
|
+
|
183
|
+
3. Override `config.path_and_suffix_generator = ->(shooter, url) {...}`,
|
184
|
+
to return `[path, suffix]` (`suffix` indicates repeated screenshots
|
185
|
+
of the same url).
|
186
|
+
|
187
|
+
4. Use `config.before_save_callback = ->(shooter) {...}` to change
|
188
|
+
`shooter.filename`, in which you can access `shooter.screenshot_size`
|
189
|
+
and other attributes.
|
190
|
+
|
191
|
+
|
163
192
|
## Tips & Tricks
|
164
193
|
|
165
194
|
### Turning Capybara::Paparazzi On and Off
|
@@ -199,9 +228,21 @@ Here's a simple approach that could work for you:
|
|
199
228
|
needed to be sure to capture everything. Currently, `visit` and `click`
|
200
229
|
are the primary triggers.
|
201
230
|
|
202
|
-
|
203
|
-
|
204
|
-
|
231
|
+
### Compatibility
|
232
|
+
|
233
|
+
Original development was done in the following environment:
|
234
|
+
- capybara 2.2.1
|
235
|
+
- poltergeist 1.5.1
|
236
|
+
- phantomjs 1.9.7
|
237
|
+
- ruby 2.0.0
|
238
|
+
- ubuntu 12.04
|
239
|
+
|
240
|
+
Capybara::Paparazzi should work with other drivers and platforms.
|
241
|
+
It is known to work on OSX, using both poltergeist and
|
242
|
+
[webkit](https://github.com/thoughtbot/capybara-webkit) as drivers.
|
243
|
+
|
244
|
+
Please open a github issue if you discover a problem with another
|
245
|
+
platform or driver.
|
205
246
|
|
206
247
|
## Related Projects
|
207
248
|
|
@@ -23,6 +23,11 @@ class Capybara::Paparazzi::Shooter
|
|
23
23
|
js_var_style: {}.merge(DEFAULT_FOLD_STYLE),
|
24
24
|
screenshot_sizes: ([] + DEFAULT_SCREENSHOT_SIZES),
|
25
25
|
file_dir: 'screenshots',
|
26
|
+
make_fewer_directories: false,
|
27
|
+
make_shorter_filenames: false,
|
28
|
+
path_and_suffix_generator: ->(shooter, url) {
|
29
|
+
shooter.path_and_suffix_for_url(url)
|
30
|
+
},
|
26
31
|
js_setup_script: ->(shooter) {
|
27
32
|
var_name = shooter.js_var_name
|
28
33
|
script = "if (!window.#{var_name}) { #{var_name} = document.createElement('DIV'); #{var_name}.className = '#{var_name}';"
|
@@ -102,7 +107,7 @@ class Capybara::Paparazzi::Shooter
|
|
102
107
|
num = @path_nums[path]
|
103
108
|
@path_nums[path] = num.to_i + 1
|
104
109
|
if num
|
105
|
-
suffix = "
|
110
|
+
suffix = "-#{num}"
|
106
111
|
if @path_nums[path+suffix]
|
107
112
|
suffix = next_suffix_for_path!(path)
|
108
113
|
end
|
@@ -120,7 +125,6 @@ class Capybara::Paparazzi::Shooter
|
|
120
125
|
attr_accessor :driver, :event_details
|
121
126
|
attr_accessor :path, :suffix
|
122
127
|
attr_accessor :do_shot, :screenshot_size, :filename
|
123
|
-
attr_accessor :before_save_callback
|
124
128
|
|
125
129
|
attr_accessor(*CONFIG_VARS.keys)
|
126
130
|
# def cv; @cv ||= self.class.config[:cv]; end
|
@@ -163,11 +167,31 @@ class Capybara::Paparazzi::Shooter
|
|
163
167
|
execute_resize_script(height)
|
164
168
|
end
|
165
169
|
|
170
|
+
def path_and_suffix_for_url(url)
|
171
|
+
path = URI.parse(url).path
|
172
|
+
path[0] = '' # remove the leading '/'
|
173
|
+
path[-1] = '' if path[-1] == '/' # remove the trailing '/'
|
174
|
+
path = 'index' if path.empty?
|
175
|
+
base = path.gsub('/','-')
|
176
|
+
if make_fewer_directories
|
177
|
+
unless make_shorter_filenames
|
178
|
+
path = path.sub(/[^\/]*$/, '') + base
|
179
|
+
end
|
180
|
+
else
|
181
|
+
path += '/'
|
182
|
+
unless make_shorter_filenames
|
183
|
+
path += base
|
184
|
+
end
|
185
|
+
end
|
186
|
+
suffix = next_suffix_for_path!(path)
|
187
|
+
[ path, suffix ]
|
188
|
+
end
|
189
|
+
|
166
190
|
|
167
191
|
private
|
168
192
|
|
169
193
|
def set_path_and_suffix
|
170
|
-
path, suffix =
|
194
|
+
path, suffix = path_and_suffix_generator.call(self, driver.current_url)
|
171
195
|
self.path = path
|
172
196
|
self.suffix = suffix
|
173
197
|
end
|
@@ -230,7 +254,10 @@ class Capybara::Paparazzi::Shooter
|
|
230
254
|
def save_snapshot(width_height_rest)
|
231
255
|
@do_shot = true
|
232
256
|
@screenshot_size = ([] + width_height_rest)
|
233
|
-
|
257
|
+
|
258
|
+
@filename = "#{file_dir}/#{path}"
|
259
|
+
@filename += '-' unless @filename[-1] == '/'
|
260
|
+
@filename += "#{width}#{suffix}.png"
|
234
261
|
|
235
262
|
resize_window(width, height)
|
236
263
|
|
@@ -257,13 +284,6 @@ class Capybara::Paparazzi::Shooter
|
|
257
284
|
[ filename, { full: true } ]
|
258
285
|
end
|
259
286
|
|
260
|
-
def path_and_suffix_for_url(url)
|
261
|
-
path = URI.parse(url).path
|
262
|
-
path += 'index' if path[-1] == '/'
|
263
|
-
suffix = next_suffix_for_path!(path)
|
264
|
-
[ path, suffix ]
|
265
|
-
end
|
266
|
-
|
267
287
|
def next_suffix_for_path!(path)
|
268
288
|
self.class.next_suffix_for_path!(path)
|
269
289
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-paparazzi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Bull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|