capybara-paparazzi 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e89cf9a779d19b87c627cd39e5c1f3af6ffec94d
4
- data.tar.gz: 868eaf3ec57b1ce4b66362e47bbb2d5314607192
3
+ metadata.gz: c0918db30feaee777aadd6602accd23680e163f3
4
+ data.tar.gz: 795c8f76228172eab0178ae0d652e791a9fd367a
5
5
  SHA512:
6
- metadata.gz: 5e74bb486bb34ffeed96221f450854bf42e4540f777a3c70aa433468de4c8b7c65e80191c159793943ca80eab3e06e1dc502982feb9117fd7365bcabd2ec418d
7
- data.tar.gz: 47e943d68d50a492271f101a8dc01a9e97c3c524a96cd8802865b32c525e30767614dd393730ad8c8663c074bad5f4f5af7532a821de135acf6ee23b1a844036
6
+ metadata.gz: 3018f50429374e6233042df23f6a9d733d32f6328c5ba160815c6eec9cfe674070041ee3787f635d68c034de24198ccaaaf78ad0861ac6e6d475005a4a3c84b9
7
+ data.tar.gz: b04c98c66a138a672304a5634e866b93ee1177e38d2c9cf568d6b4f98b070e45c2d02da32fe2fc797202fc85becdd2d23bb179b1b8efa1e6195d70c893b6ee51
data/README.md CHANGED
@@ -87,13 +87,13 @@ Here's a fairly complete list of things you can do:
87
87
 
88
88
  ```ruby
89
89
  Capybara::Paparazzi.config do |config|
90
- config.js_var_name = 'MY_DIV' # Name of the div used to draw the fold line.
90
+ config.js_var_name = 'MY_FOLD_DIV' # Name of the div used to draw the fold line.
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
94
  # config.js_setup_script = ->(shooter){ ... }
95
95
  config.js_resize_script = ->(shooter, height) {
96
- "#{shooter.js_var_name}.style.height = '#{height}px'; MY_DIV.textContent = #{shooter.screenshot_size.inspect.to_json}; MY_DIV.style.fontSize = '#{height/4}px';"
96
+ "#{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';"
97
97
  }
98
98
  # config.js_cleanup_script = ->(shooter){}
99
99
  config.before_save_callback = ->(shooter) {
@@ -106,7 +106,31 @@ end
106
106
 
107
107
  For the default settings, see [shooter.rb](https://github.com/sbull/capybara-paparazzi/blob/master/lib/capybara/paparazzi/shooter.rb).
108
108
 
109
- ### Manual screenshots
109
+ ### Skipping Screenshots
110
+
111
+ Many test flows might have common steps that are just plain redundant
112
+ to keep capturing. Disabling Capybara::Paparazzi for those flows could
113
+ be useful. Here's how:
114
+ ```ruby
115
+ without_snapshots do
116
+ visit root_path # <-- your stuff
117
+ end
118
+ ```
119
+
120
+ `without_snapshots` is also known as `without_paparazzi`.
121
+
122
+ You can also disable Capybara::Paparazzi in scenarios by calling
123
+
124
+ turn_snapshots_off
125
+
126
+ (aka `turn_paparazzi_off`), but then you'll have to turn it back on
127
+ for future scenarios by calling
128
+
129
+ turn_snapshots_on
130
+
131
+ (aka `turn_paparazzi_on`).
132
+
133
+ ### Manual Screenshots
110
134
 
111
135
  Try as it might, Capybara::Paparazzi could miss some photos that you
112
136
  want it to take, particularly if you're using javascript to change
@@ -128,7 +152,13 @@ phone, tablet, and desktop browser dimensions. The most important
128
152
  feature is the width. The height is used to draw the "fold" line - the
129
153
  default sizes attempt to take into account the browser chrome that
130
154
  gets added to the top and bottom of browser windows, which results in
131
- a shorter view than the actual device height.
155
+ a shorter view than the actual device height. As indicated above,
156
+ you can change the screenshot sizes with
157
+
158
+ config.screenshot_sizes = [ [ 1920, 1080, 'my big', 'screen' ] ]
159
+
160
+ The first 2 values in the array are width and height, but the whole array
161
+ is made available for use in customized configuration scripts.
132
162
 
133
163
  ## Tips & Tricks
134
164
 
@@ -165,10 +195,14 @@ Here's a simple approach that could work for you:
165
195
 
166
196
  ## TODO
167
197
 
168
- The photo-capturing triggers may be incomplete, and enhancements may be
198
+ - The photo-capturing triggers may be incomplete, and enhancements may be
169
199
  needed to be sure to capture everything. Currently, `visit` and `click`
170
200
  are the primary triggers.
171
201
 
202
+ - Development has only been done with Poltergeist on an Ubuntu
203
+ virtual machine, but the intent is to work with other drivers & setups.
204
+ So feedback on that would be appreciated.
205
+
172
206
  ## Related Projects
173
207
 
174
208
  - [Capybara](https://github.com/jnicklas/capybara)
@@ -205,7 +239,7 @@ Some useful one-liners for the above:
205
239
 
206
240
  In `capybara-paparazzi` repository:
207
241
 
208
- gem uninstall capybara-paparazzi && gem build capybara-paparazzi.gemspec && gem install ./capybara-paparazzi-0.0.1.new.gem Successfully uninstalled capybara-paparazzi-0.0.1.new
242
+ gem uninstall capybara-paparazzi && gem build capybara-paparazzi.gemspec && gem install ./capybara-paparazzi-0.0.1.new.gem
209
243
 
210
244
  In your project:
211
245
 
@@ -35,6 +35,20 @@ module Capybara::Paparazzi
35
35
  end
36
36
  end
37
37
 
38
+ def without_snapshots(driver, &block)
39
+ Capybara::Paparazzi::Shooter.without_snapshots(driver) do
40
+ yield
41
+ end
42
+ end
43
+
44
+ def turn_off(driver)
45
+ Capybara::Paparazzi::Shooter.turn_off(driver)
46
+ end
47
+
48
+ def turn_on(driver)
49
+ Capybara::Paparazzi::Shooter.turn_on(driver)
50
+ end
51
+
38
52
  end # ClassMethods
39
53
 
40
54
  extend ClassMethods
@@ -1,5 +1,9 @@
1
1
  module Capybara::Paparazzi::Driver
2
2
 
3
+ def capybara_paparazzi_settings
4
+ @capybara_paparazzi_settings ||= {}
5
+ end
6
+
3
7
  def visit(*args)
4
8
  response = super(*args)
5
9
  Capybara::Paparazzi.take_snapshots(self, :visit, args)
@@ -4,9 +4,28 @@ module Capybara::Paparazzi::DSL
4
4
  Capybara::Paparazzi.take_snapshots_if_following(page.driver, :manual, args)
5
5
  end
6
6
 
7
+ def turn_paparazzi_off
8
+ Capybara::Paparazzi.turn_off(page.driver)
9
+ end
10
+
11
+ def turn_paparazzi_on
12
+ Capybara::Paparazzi.turn_on(page.driver)
13
+ end
14
+
15
+ def without_paparazzi(&block)
16
+ Capybara::Paparazzi.without_snapshots(page.driver) do
17
+ yield
18
+ end
19
+ end
20
+
7
21
  def self.included(mod)
8
- unless mod.method_defined?(:take_snapshots)
9
- mod.send(:alias_method, :take_snapshots, :paparazzi_take_snapshots)
22
+ [
23
+ [ :paparazzi_take_snapshots, :take_snapshots ],
24
+ [ :without_paparazzi, :without_snapshots ],
25
+ [ :turn_paparazzi_off, :turn_snapshots_off ],
26
+ [ :turn_paparazzi_on, :turn_snapshots_on ],
27
+ ].each do |meth, aka|
28
+ mod.send(:alias_method, aka, meth) unless mod.method_defined?(aka)
10
29
  end
11
30
  end
12
31
 
@@ -14,17 +14,18 @@ class Capybara::Paparazzi::Shooter
14
14
  left: '0',
15
15
  width: '100%',
16
16
  zIndex: 999999,
17
- borderBottom: '1px solid red',
17
+ background: 'none',
18
+ borderBottom: '3px dashed red',
18
19
  }.freeze
19
20
 
20
21
  CONFIG_VARS = {
21
- js_var_name: 'THE_FOLD',
22
+ js_var_name: 'CAPYBARA_PAPARAZZI_FOLD',
22
23
  js_var_style: {}.merge(DEFAULT_FOLD_STYLE),
23
24
  screenshot_sizes: ([] + DEFAULT_SCREENSHOT_SIZES),
24
25
  file_dir: 'screenshots',
25
26
  js_setup_script: ->(shooter) {
26
27
  var_name = shooter.js_var_name
27
- script = "if (!window.#{var_name}) { #{var_name} = document.createElement('DIV');"
28
+ script = "if (!window.#{var_name}) { #{var_name} = document.createElement('DIV'); #{var_name}.className = '#{var_name}';"
28
29
  shooter.js_var_style.each do |prop_name, prop_val|
29
30
  script += "#{var_name}.style.#{prop_name} = #{prop_val.to_json};"
30
31
  end
@@ -59,7 +60,40 @@ class Capybara::Paparazzi::Shooter
59
60
 
60
61
  def take_snapshots(driver, event_details=nil)
61
62
  # TODO: Be smarter. One shooter per driver, but avoid memory leaks (be mindful of Guard, etc.).
62
- new(driver, event_details).take_snapshots
63
+ unless driver.capybara_paparazzi_settings[:block_disabled] || driver.capybara_paparazzi_settings[:manually_disabled]
64
+ new(driver, event_details).take_snapshots
65
+ end
66
+ end
67
+
68
+ def without_snapshots(driver, &block)
69
+ is_paparazzi = is_paparazzi?(driver)
70
+ if is_paparazzi
71
+ old_val = driver.capybara_paparazzi_settings[:block_disabled]
72
+ driver.capybara_paparazzi_settings[:block_disabled] = true
73
+ end
74
+ begin
75
+ yield
76
+ ensure
77
+ if is_paparazzi
78
+ driver.capybara_paparazzi_settings[:block_disabled] = old_val
79
+ end
80
+ end
81
+ end
82
+
83
+ def turn_off(driver)
84
+ if is_paparazzi?(driver)
85
+ driver.capybara_paparazzi_settings[:manually_disabled] = true
86
+ end
87
+ end
88
+
89
+ def turn_on(driver)
90
+ if is_paparazzi?(driver)
91
+ driver.capybara_paparazzi_settings[:manually_disabled] = false
92
+ end
93
+ end
94
+
95
+ def is_paparazzi?(driver)
96
+ driver.is_a?(Capybara::Paparazzi::Driver)
63
97
  end
64
98
 
65
99
  def next_suffix_for_path!(path)
@@ -125,6 +159,20 @@ class Capybara::Paparazzi::Shooter
125
159
  end
126
160
 
127
161
  def resize_window(width, height)
162
+ driver_resize_window(width, height)
163
+ execute_resize_script(height)
164
+ end
165
+
166
+
167
+ private
168
+
169
+ def set_path_and_suffix
170
+ path, suffix = path_and_suffix_for_url(driver.current_url)
171
+ self.path = path
172
+ self.suffix = suffix
173
+ end
174
+
175
+ def driver_resize_window(width, height)
128
176
  begin
129
177
  if driver.respond_to?(:resize) # Poltergeist
130
178
  driver.resize(width, height)
@@ -135,17 +183,8 @@ class Capybara::Paparazzi::Shooter
135
183
  end
136
184
  rescue => e
137
185
  log("Error while resizing window: #{e}")
186
+ raise
138
187
  end
139
- execute_resize_script(height)
140
- end
141
-
142
-
143
- private
144
-
145
- def set_path_and_suffix
146
- path, suffix = path_and_suffix_for_url(driver.current_url)
147
- self.path = path
148
- self.suffix = suffix
149
188
  end
150
189
 
151
190
  def execute_setup_script
@@ -161,12 +200,30 @@ class Capybara::Paparazzi::Shooter
161
200
  end
162
201
  rescue => e
163
202
  log("#{e.message}\nJavascript: #{script_text}")
203
+ raise
164
204
  end
165
205
  end
166
206
 
167
207
  def save_snapshots
168
- screenshot_sizes.each do |w_h_rest|
169
- save_snapshot(w_h_rest)
208
+ # In some cases, using screen sizes other than the default
209
+ # can cause failures in Poltergeist, when using the default
210
+ # screen size does not. So be sure to always reset to the
211
+ # original screen size to ensure test behavior consistent with
212
+ # the non-Capybara::Paparazzi tests.
213
+ # Example error:
214
+ # Firing a click at co-ordinates [703, 654] failed. Poltergeist detected another element with CSS selector '' at this position. It may be overlapping the element you are trying to interact with. If you don't care about overlapping elements, try using node.trigger('click').
215
+
216
+ begin
217
+ orig_width, orig_height = driver.evaluate_script("[window.innerWidth, window.innerHeight]")
218
+ screenshot_sizes.each do |w_h_rest|
219
+ save_snapshot(w_h_rest)
220
+ end
221
+ ensure
222
+ begin
223
+ driver_resize_window(orig_width, orig_height)
224
+ rescue => e
225
+ log("Error restoring original window size to #{orig_width}x#{orig_height}: #{e}")
226
+ end
170
227
  end
171
228
  end
172
229
 
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Paparazzi
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  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.2
4
+ version: 0.0.3
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-07-29 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler