calabash 2.0.0.pre11 → 2.0.0.prelegacy

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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/bin/calabash +4 -3
  4. data/lib/calabash/android/adb.rb +37 -34
  5. data/lib/calabash/android/application.rb +1 -1
  6. data/lib/calabash/android/build/builder.rb +1 -1
  7. data/lib/calabash/android/build/java_keystore.rb +1 -1
  8. data/lib/calabash/android/build/resigner.rb +1 -1
  9. data/lib/calabash/android/device.rb +46 -204
  10. data/lib/calabash/android/environment.rb +1 -14
  11. data/lib/calabash/android/gestures.rb +22 -6
  12. data/lib/calabash/android/interactions.rb +17 -14
  13. data/lib/calabash/android/legacy.rb +141 -4
  14. data/lib/calabash/android/lib/.irbrc +1 -9
  15. data/lib/calabash/android/lib/AndroidManifest.xml +2 -23
  16. data/lib/calabash/android/lib/TestServer.apk +0 -0
  17. data/lib/calabash/android/life_cycle.rb +3 -3
  18. data/lib/calabash/android/orientation.rb +8 -8
  19. data/lib/calabash/android/physical_buttons.rb +16 -19
  20. data/lib/calabash/android/server.rb +1 -6
  21. data/lib/calabash/android/text.rb +12 -12
  22. data/lib/calabash/android.rb +26 -92
  23. data/lib/calabash/application.rb +0 -3
  24. data/lib/calabash/cli/generate.rb +18 -8
  25. data/lib/calabash/cli/helpers.rb +9 -4
  26. data/lib/calabash/cli/run.rb +1 -1
  27. data/lib/calabash/console_helpers.rb +11 -179
  28. data/lib/calabash/device.rb +19 -4
  29. data/lib/calabash/gestures.rb +198 -292
  30. data/lib/calabash/http/retriable_client.rb +3 -18
  31. data/lib/calabash/http.rb +0 -1
  32. data/lib/calabash/interactions.rb +40 -3
  33. data/lib/calabash/ios/conditions.rb +1 -1
  34. data/lib/calabash/ios/console_helpers.rb +2 -2
  35. data/lib/calabash/ios/date_picker.rb +8 -10
  36. data/lib/calabash/ios/device/device_implementation.rb +21 -9
  37. data/lib/calabash/ios/device/gestures_mixin.rb +55 -53
  38. data/lib/calabash/ios/device/keyboard_mixin.rb +0 -21
  39. data/lib/calabash/ios/device/rotation_mixin.rb +65 -3
  40. data/lib/calabash/ios/device/text_mixin.rb +21 -0
  41. data/lib/calabash/ios/device.rb +1 -0
  42. data/lib/calabash/ios/gestures.rb +90 -24
  43. data/lib/calabash/ios/interactions.rb +6 -1
  44. data/lib/calabash/ios/lib/.irbrc +2 -9
  45. data/lib/calabash/ios/orientation.rb +8 -8
  46. data/lib/calabash/ios/runtime.rb +14 -14
  47. data/lib/calabash/ios/scroll.rb +17 -25
  48. data/lib/calabash/ios/slider.rb +18 -11
  49. data/lib/calabash/ios/text.rb +74 -20
  50. data/lib/calabash/ios/uia.rb +1 -1
  51. data/lib/calabash/ios.rb +16 -77
  52. data/lib/calabash/legacy.rb +6 -9
  53. data/lib/calabash/lib/skeleton/{Gemfile.skeleton → Gemfile} +0 -0
  54. data/lib/calabash/lib/skeleton/config/{cucumber.yml.skeleton → cucumber.yml} +0 -0
  55. data/lib/calabash/lib/skeleton/features/{sample.feature.skeleton → sample.feature} +0 -0
  56. data/lib/calabash/lib/skeleton/features/step_definitions/{sample_steps.rb.skeleton → calabash_steps.rb} +8 -8
  57. data/lib/calabash/lib/skeleton/features/support/{dry_run.rb.skeleton → dry_run.rb} +5 -2
  58. data/lib/calabash/lib/skeleton/features/support/{env.rb.skeleton → env.rb} +8 -2
  59. data/lib/calabash/lib/skeleton/features/support/hooks.rb +83 -0
  60. data/lib/calabash/life_cycle.rb +8 -16
  61. data/lib/calabash/location.rb +15 -14
  62. data/lib/calabash/orientation.rb +8 -8
  63. data/lib/calabash/page.rb +4 -1
  64. data/lib/calabash/screenshot.rb +3 -3
  65. data/lib/calabash/text.rb +19 -31
  66. data/lib/calabash/utility.rb +8 -41
  67. data/lib/calabash/version.rb +1 -1
  68. data/lib/calabash/wait.rb +192 -177
  69. data/lib/calabash.rb +10 -53
  70. metadata +32 -43
  71. data/lib/calabash/android/device/helper_application.rb +0 -95
  72. data/lib/calabash/android/lib/HelperApplication.apk +0 -0
  73. data/lib/calabash/android/lib/HelperApplicationTestServer.apk +0 -0
  74. data/lib/calabash/android/web.rb +0 -12
  75. data/lib/calabash/http/forwarding_client.rb +0 -23
  76. data/lib/calabash/internal.rb +0 -48
  77. data/lib/calabash/ios/automator/automator.rb +0 -217
  78. data/lib/calabash/ios/automator/coordinates.rb +0 -37
  79. data/lib/calabash/ios/automator/device_agent.rb +0 -379
  80. data/lib/calabash/ios/automator.rb +0 -9
  81. data/lib/calabash/ios/legacy.rb +0 -6
  82. data/lib/calabash/ios/web.rb +0 -10
  83. data/lib/calabash/lib/skeleton/features/support/hooks.rb.skeleton +0 -34
  84. data/lib/calabash/retry.rb +0 -33
  85. data/lib/calabash/stubs.rb +0 -21
  86. data/lib/calabash/web.rb +0 -44
data/lib/calabash/wait.rb CHANGED
@@ -2,7 +2,7 @@ module Calabash
2
2
 
3
3
  # A public API for waiting for things to happen.
4
4
  module Wait
5
- # Default error indicating a timeout
5
+ # @!visibility private
6
6
  class TimeoutError < RuntimeError
7
7
  end
8
8
 
@@ -13,7 +13,7 @@ module Calabash
13
13
  timeout: Environment::WAIT_TIMEOUT,
14
14
 
15
15
  # default message (String or Proc) if timeout occurs
16
- timeout_message: lambda do |options|
16
+ message: lambda do |options|
17
17
  "Timed out after waiting for #{options[:timeout]} seconds..."
18
18
  end,
19
19
 
@@ -21,60 +21,52 @@ module Calabash
21
21
  retry_frequency: 0.1,
22
22
 
23
23
  # default exception type to raise when the timeout is exceeded
24
- exception_class: Calabash::Wait::TimeoutError
24
+ exception_class: Calabash::Wait::TimeoutError,
25
+
26
+ # whether to embed a screenshot on failure
27
+ screenshot_on_error: true
25
28
  }
26
29
 
27
30
  # Returns the default wait options.
28
- #
29
- # @example
30
- # # Get the current timeout message
31
- # Calabash::Wait.default_options[:timeout_message]
32
- #
33
- # @example
34
- # Calabash::Wait.default_options[:timeout] = 60
35
- #
36
- # @see @@default_options
37
31
  # @return [Hash] Key/value pairs describing the wait options.
38
32
  def self.default_options
39
33
  @@default_options
40
34
  end
41
35
 
36
+ # Sets the default wait options.
37
+ # @param [Hash] value The new default wait options.
38
+ def self.default_options=(value)
39
+ @@default_options = value
40
+ end
41
+
42
42
  # Evaluates the block given. If the execution time of the block exceeds
43
- # `timeout` it will raise a `exception_class` (default:
44
- # {Calabash::Wait.default_options
45
- # Calabash::Wait.default_options[:exception_class]}).
43
+ # `timeout` it will raise a TimeoutError.
46
44
  #
47
45
  # If you have an explicit or implicit loop in your block, or
48
46
  # you want to limit the possible execution time of your block, use
49
- # {Calabash::Wait#with_timeout cal.with_timeout}
47
+ # `with_timeout`.
50
48
  #
51
49
  # @example
52
- # # If the 'PictureRow' view does not exist, keep panning up.
53
- # cal.with_timeout(15, 'Could not find picture row') do
54
- # cal.pan_screen_up until cal.view_exists?("PictureRow")
50
+ # # If the 'PictureRow' view does not exist, keep scrolling down.
51
+ # with_timeout(15, 'Could not find picture row') do
52
+ # scroll_down until view_exists?("PictureRow")
55
53
  # end
56
54
  #
57
- # @example
58
- # # Pan up **at least once** and continue pan up until the
55
+ # # Scroll down **at least once** and continue scrolling down until the
59
56
  # # 'PictureRow' exists.
60
- # cal.wait_for('Could not find picture row') do
61
- # cal.pan_screen_up
62
- # cal.view_exists?("PictureRow")
57
+ # wait_for(15, 'Could not find picture row') do
58
+ # scroll_down
59
+ # view_exists?("PictureRow")
63
60
  # end
64
61
  #
65
62
  # @param [Number] timeout The time before failing
66
63
  # @param [String, Proc] timeout_message The error message if timed out
67
- # @param [Class] exception_class
68
- # (default: {Calabash::Wait.default_options
69
- # Calabash::Wait.default_options[:exception_class]}) The exception type
70
- # raised if timed out
71
- # @return The returned value of the block given
64
+ # @param [Class] exception_class The exception type raised if timed out
65
+ # @return The returned value of `block`
72
66
  # @raise [ArgumentError] If an invalid timeout is given (<= 0)
73
67
  # @raise [ArgumentError] If no timeout_message is given
74
68
  # @raise [ArgumentError] If no block is given
75
- def with_timeout(timeout, timeout_message,
76
- exception_class: Wait.default_options[:exception_class],
77
- &block)
69
+ def with_timeout(timeout, timeout_message, exception_class = TimeoutError, &block)
78
70
  if timeout_message.nil? ||
79
71
  (timeout_message.is_a?(String) && timeout_message.empty?)
80
72
  raise ArgumentError, 'You must provide a timeout message'
@@ -111,7 +103,7 @@ module Calabash
111
103
  end
112
104
 
113
105
  if failed
114
- raise exception_class, message
106
+ fail(exception_class, message)
115
107
  end
116
108
  end
117
109
 
@@ -121,43 +113,31 @@ module Calabash
121
113
  # If the block does not evaluate to truthy within the given timeout
122
114
  # an TimeoutError will be raised.
123
115
  #
124
- # The default timeout will be {Calabash::Wait.default_options
125
- # Wait.default_options[:timeout]}.
126
- #
127
- # @example
128
- # # Pan up **at least once** and continue pan up until the
129
- # # 'PictureRow' exists.
130
- # cal.wait_for('Could not find picture row') do
131
- # cal.pan_screen_up
132
- # cal.view_exists?("PictureRow")
133
- # end
116
+ # The default timeout will be `Wait.default_options[:timeout]`.
134
117
  #
135
118
  # @see Calabash::Wait#with_timeout
119
+ # @see Calabash::Environment::WAIT_TIMEOUT
120
+ # @see Calabash::Wait.default_options
136
121
  #
137
122
  # @param [String, Proc] timeout_message The error message if timed out.
138
- # @param [Number] timeout (default: {Calabash::Wait.default_options
139
- # Calabash::Wait.default_options[:timeout]}) The time before
140
- # @param [Number] retry_frequency (default: {Calabash::Wait.default_options
141
- # Calabash::Wait.default_options[:retry_frequency]}) How often to check
142
- # for the block to be truthy
143
- # @param [Class] exception_class
144
- # (default: {Calabash::Wait.default_options
145
- # Calabash::Wait.default_options[:exception_class]}) The exception type
146
- # raised if timed out
123
+ # @param [Hash] options Used to control the behavior of the wait.
124
+ # @option options [Number] :timeout (30) How long to wait before timing out.
125
+ # @option options [Number] :retry_frequency (0.3) How often to check for
126
+ # the condition block to be truthy.
127
+ # @option options [Boolean] :screenshot_on_error (true) Take a screenshot
128
+ # if the block fails to be truthy or an error is raised in the block.
147
129
  # @return The returned value of `block` if it is truthy
148
- def wait_for(timeout_message,
149
- timeout: Calabash::Wait.default_options[:timeout],
150
- retry_frequency: Calabash::Wait.default_options[:retry_frequency],
151
- exception_class: Calabash::Wait.default_options[:exception_class],
152
- &block)
153
- with_timeout(timeout, timeout_message,
154
- exception_class: exception_class) do
130
+ def wait_for(timeout_message, options={}, &block)
131
+ wait_options = Wait.default_options.merge(options)
132
+ timeout = wait_options[:timeout]
133
+
134
+ with_timeout(timeout, timeout_message, wait_options[:exception_class]) do
155
135
  loop do
156
136
  value = block.call
157
137
 
158
138
  return value if value
159
139
 
160
- sleep(retry_frequency)
140
+ sleep(wait_options[:retry_frequency])
161
141
  end
162
142
  end
163
143
  end
@@ -165,69 +145,62 @@ module Calabash
165
145
  # Waits for `query` to match one or more views.
166
146
  #
167
147
  # @example
168
- # cal.wait_for_view({marked: 'mark'})
148
+ # wait_for_view({marked: 'mark'})
169
149
  #
170
150
  # @example
171
- # cal.wait_for_view({marked: 'login'},
172
- # timeout_message: "Did not see login button")
173
- #
174
- # @example
175
- # text = cal.wait_for_view("myview")['text']
176
- #
177
- # @see Calabash::Wait#wait_for for optional parameters
151
+ # text = wait_for_view("myview")['text']
178
152
  #
179
153
  # @param [String, Hash, Calabash::Query] query Query to match view
154
+ # @see Calabash::Wait#with_timeout for options
180
155
  # @return [Hash] The first view matching `query`.
181
- # @raise [ViewNotFoundError] If `query` do not match at least one view.
182
- def wait_for_view(query,
183
- timeout: Calabash::Wait.default_options[:timeout],
184
- timeout_message: nil,
185
- retry_frequency: Calabash::Wait.default_options[:retry_frequency])
156
+ def wait_for_view(query, options={})
186
157
  if query.nil?
187
158
  raise ArgumentError, 'Query cannot be nil'
188
159
  end
189
160
 
190
- timeout_message ||= lambda do |wait_options|
191
- "Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to match a view"
161
+ defaults = Wait.default_options.dup
162
+
163
+ defaults[:message] = lambda do |wait_options|
164
+ "Waited #{wait_options[:timeout]} seconds for #{parse_query_list(query)} to match a view"
192
165
  end
193
166
 
194
- wait_for(timeout_message,
195
- timeout: timeout,
196
- retry_frequency: retry_frequency,
197
- exception_class: ViewNotFoundError) do
198
- result = query(query)
199
- !result.empty? && result
167
+ defaults[:exception_class] = ViewNotFoundError
168
+
169
+ timeout_options = defaults.merge(options)
170
+
171
+ wait_for(timeout_options[:message],
172
+ {timeout: timeout_options[:timeout],
173
+ exception_class: timeout_options[:exception_class],
174
+ retry_frequency: timeout_options[:retry_frequency]}) do
175
+ view_exists?(query)
200
176
  end.first
201
177
  end
202
178
 
203
179
  # Waits for all `queries` to simultaneously match at least one view.
204
180
  #
205
- # @example
206
- # cal.wait_for_views({id: 'foo'}, {id: 'bar'})
207
- #
208
- # @see Calabash::Wait#wait_for for optional parameters
209
- #
210
181
  # @param [String, Hash, Calabash::Query] queries List of queries or a
211
182
  # query.
212
- # @return The returned value is undefined
213
- # @raise [ViewNotFoundError] If `queries` do not all match at least one
214
- # view.
215
- def wait_for_views(*queries,
216
- timeout: Calabash::Wait.default_options[:timeout],
217
- timeout_message: nil,
218
- retry_frequency: Calabash::Wait.default_options[:retry_frequency])
183
+ #
184
+ # @see Calabash::Wait#with_timeout for options
185
+ # @return [void] The return value for this method is undefined.
186
+ def wait_for_views(*queries, **options)
219
187
  if queries.nil? || queries.any?(&:nil?)
220
188
  raise ArgumentError, 'Query cannot be nil'
221
189
  end
222
190
 
223
- timeout_message ||= lambda do |wait_options|
224
- "Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each match a view"
191
+ defaults = Wait.default_options.dup
192
+ defaults[:message] = lambda do |wait_options|
193
+ "Waited #{wait_options[:timeout]} seconds for #{parse_query_list(queries)} to each match a view"
225
194
  end
226
195
 
227
- wait_for(timeout_message,
228
- timeout: timeout,
229
- retry_frequency: retry_frequency,
230
- exception_class: ViewNotFoundError) do
196
+ defaults[:exception_class] = ViewNotFoundError
197
+
198
+ timeout_options = defaults.merge(options)
199
+
200
+ wait_for(timeout_options[:message],
201
+ {timeout: timeout_options[:timeout],
202
+ exception_class: timeout_options[:exception_class],
203
+ retry_frequency: timeout_options[:retry_frequency]}) do
231
204
  views_exist?(*queries)
232
205
  end
233
206
 
@@ -238,64 +211,54 @@ module Calabash
238
211
 
239
212
  # Waits for `query` not to match any views
240
213
  #
241
- # @example
242
- # cal.wait_for_no_view({marked: 'mark'})
243
- #
244
- # @example
245
- # cal.wait_for_no_view({marked: 'login'},
246
- # timeout_message: "Login button did not disappear")
247
- #
248
- # @see Calabash::Wait#wait_for for optional parameters
249
- #
250
214
  # @param [String, Hash, Calabash::Query] query Query to match view
251
- # @raise [ViewFoundError] If `query` do not match at least one view.
252
- def wait_for_no_view(query,
253
- timeout: Calabash::Wait.default_options[:timeout],
254
- timeout_message: nil,
255
- retry_frequency: Calabash::Wait.default_options[:retry_frequency])
215
+ # @see Calabash::Wait#with_timeout for options
216
+ def wait_for_no_view(query, options={})
256
217
  if query.nil?
257
218
  raise ArgumentError, 'Query cannot be nil'
258
219
  end
259
220
 
260
- timeout_message ||= lambda do |wait_options|
261
- "Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(query)} to not match any view"
221
+ defaults = Wait.default_options.dup
222
+ defaults[:message] = lambda do |wait_options|
223
+ "Waited #{wait_options[:timeout]} seconds for #{parse_query_list(query)} to not match any view"
262
224
  end
263
225
 
264
- wait_for(timeout_message,
265
- timeout: timeout,
266
- retry_frequency: retry_frequency,
267
- exception_class: ViewFoundError) do
226
+ defaults[:exception_class] = ViewFoundError
227
+
228
+ timeout_options = defaults.merge(options)
229
+
230
+ wait_for(timeout_options[:message],
231
+ {timeout: timeout_options[:timeout],
232
+ exception_class: timeout_options[:exception_class],
233
+ retry_frequency: timeout_options[:retry_frequency]}) do
268
234
  !view_exists?(query)
269
235
  end
270
236
  end
271
237
 
272
238
  # Waits for all `queries` to simultaneously match no views
273
239
  #
274
- # @example
275
- # cal.wait_for_no_views({id: 'foo'}, {id: 'bar'})
276
- #
277
- # @see Calabash::Wait#wait_for for optional parameters
278
- #
279
240
  # @param [String, Hash, Calabash::Query] queries List of queries or a
280
241
  # query.
281
- # @raise [ViewNotFoundError] If `queries` do not all match at least one
282
- # view.
283
- def wait_for_no_views(*queries,
284
- timeout: Calabash::Wait.default_options[:timeout],
285
- timeout_message: nil,
286
- retry_frequency: Calabash::Wait.default_options[:retry_frequency])
242
+ #
243
+ # @see Calabash::Wait#with_timeout for options
244
+ def wait_for_no_views(*queries, **options)
287
245
  if queries.nil? || queries.any?(&:nil?)
288
246
  raise ArgumentError, 'Query cannot be nil'
289
247
  end
290
248
 
291
- timeout_message ||= lambda do |wait_options|
292
- "Waited #{wait_options[:timeout]} seconds for #{Wait.parse_query_list(queries)} to each not match any view"
249
+ defaults = Wait.default_options.dup
250
+ defaults[:message] = lambda do |wait_options|
251
+ "Waited #{wait_options[:timeout]} seconds for #{parse_query_list(queries)} to each not match any view"
293
252
  end
294
253
 
295
- wait_for(timeout_message,
296
- timeout: timeout,
297
- retry_frequency: retry_frequency,
298
- exception_class: ViewFoundError) do
254
+ defaults[:exception_class] = ViewFoundError
255
+
256
+ timeout_options = defaults.merge(options)
257
+
258
+ wait_for(timeout_options[:message],
259
+ {timeout: timeout_options[:timeout],
260
+ exception_class: timeout_options[:exception_class],
261
+ retry_frequency: timeout_options[:retry_frequency]}) do
299
262
  !views_exist?(*queries)
300
263
  end
301
264
  end
@@ -303,7 +266,7 @@ module Calabash
303
266
  # Does the given `query` match at least one view?
304
267
  #
305
268
  # @param [String, Hash, Calabash::Query] query Query to match view
306
- # @return [Boolean] Returns true if the `query` matches at least one view
269
+ # @return [Object] Returns truthy if the `query` matches at least one view
307
270
  # @raise [ArgumentError] If given an invalid `query`
308
271
  def view_exists?(query)
309
272
  if query.nil?
@@ -312,15 +275,19 @@ module Calabash
312
275
 
313
276
  result = query(query)
314
277
 
315
- !result.empty?
278
+ if result.empty?
279
+ false
280
+ else
281
+ result
282
+ end
316
283
  end
317
284
 
318
285
  # Does the given `queries` all match at least one view?
319
286
  #
320
287
  # @param [String, Hash, Calabash::Query] queries List of queries or a
321
288
  # query
322
- # @return [Boolean] Returns true if the `queries` all match at least one
323
- # view
289
+ #
290
+ # @return Returns truthy if the `queries` all match at least one view
324
291
  # @raise [ArgumentError] If given an invalid list of queries
325
292
  def views_exist?(*queries)
326
293
  if queries.nil? || queries.any?(&:nil?)
@@ -329,7 +296,11 @@ module Calabash
329
296
 
330
297
  results = queries.map{|query| view_exists?(query)}
331
298
 
332
- results.all?
299
+ if results.all?
300
+ results
301
+ else
302
+ false
303
+ end
333
304
  end
334
305
 
335
306
  # Expect `query` to match at least one view. Raise an exception if it does
@@ -345,7 +316,7 @@ module Calabash
345
316
 
346
317
  unless view_exists?(query)
347
318
  raise ViewNotFoundError,
348
- "No view matched #{Wait.parse_query_list(query)}"
319
+ "No view matched #{parse_query_list(query)}"
349
320
  end
350
321
 
351
322
  true
@@ -368,7 +339,7 @@ module Calabash
368
339
 
369
340
  unless views_exist?(*queries)
370
341
  raise ViewNotFoundError,
371
- "Not all queries #{Wait.parse_query_list(queries)} matched a view"
342
+ "Not all queries #{parse_query_list(queries)} matched a view"
372
343
  end
373
344
 
374
345
  true
@@ -387,7 +358,7 @@ module Calabash
387
358
  end
388
359
 
389
360
  if view_exists?(query)
390
- raise ViewFoundError, "A view matched #{Wait.parse_query_list(query)}"
361
+ raise ViewFoundError, "A view matched #{parse_query_list(query)}"
391
362
  end
392
363
 
393
364
  true
@@ -408,7 +379,7 @@ module Calabash
408
379
 
409
380
  if queries.map{|query| view_exists?(query)}.any?
410
381
  raise ViewFoundError,
411
- "Some views matched #{Wait.parse_query_list(queries)}"
382
+ "Some views matched #{parse_query_list(queries)}"
412
383
  end
413
384
 
414
385
  true
@@ -418,52 +389,84 @@ module Calabash
418
389
 
419
390
  # Waits for a view containing `text`.
420
391
  #
421
- # @see Calabash::Wait#wait_for_view
422
- #
423
392
  # @param text [String] Text to look for
424
393
  # @return [Object] The view matched by the text query
425
- def wait_for_text(text,
426
- timeout: Calabash::Wait.default_options[:timeout],
427
- timeout_message: nil,
428
- retry_frequency: Calabash::Wait.default_options[:retry_frequency])
429
-
430
- wait_for_view("* {text CONTAINS[c] '#{text}'}",
431
- timeout: timeout,
432
- timeout_message: timeout_message,
433
- retry_frequency: retry_frequency)
394
+ # @see Calabash::Wait#wait_for_view
395
+ def wait_for_text(text, options={})
396
+ wait_for_view("* {text CONTAINS[c] '#{text}'}", options)
434
397
  end
435
398
 
436
399
  # Waits for no views containing `text`.
437
400
  #
438
- # @see Calabash::Wait#wait_for_view
439
- #
440
401
  # @param text [String] Text to look for
441
- # @return [Object] The view matched by the text query
442
- def wait_for_no_text(text,
443
- timeout: Calabash::Wait.default_options[:timeout],
444
- timeout_message: nil,
445
- retry_frequency: Calabash::Wait.default_options[:retry_frequency])
446
-
447
- wait_for_no_view("* {text CONTAINS[c] '#{text}'}",
448
- timeout: timeout,
449
- timeout_message: timeout_message,
450
- retry_frequency: retry_frequency)
402
+ # @see Calabash::Wait#wait_for_no_view
403
+ def wait_for_text_to_disappear(text, options={})
404
+ wait_for_no_view("* {text CONTAINS[c] '#{text}'}", options)
451
405
  end
452
406
 
453
- # Query matched an unexpected set of views
454
- class UnexpectedMatchError < RuntimeError
455
- end
407
+ # Raises an exception. Embeds a screenshot if
408
+ # Calabash::Wait#default_options[:screenshot_on_error] is true. The fail
409
+ # method should be used when the test should fail and stop executing. Do
410
+ # not use fail if you intent on rescuing the error raised without
411
+ # re-raising.
412
+ #
413
+ # @example
414
+ # unless view_exists?("* marked:'login'")
415
+ # fail('Did not see "login" button')
416
+ # end
417
+ #
418
+ # @example
419
+ # entries = query("ListEntry").length
420
+ #
421
+ # if entries < 5
422
+ # fail(MyError, "Should see at least 5 entries, saw #{entries}")
423
+ # end
424
+ #
425
+ # @raise [RuntimeError, StandardError] By default, raises a RuntimeError with
426
+ # `message`. You can pass in your own Exception class to override the
427
+ # the default behavior.
428
+ def fail(*several_variants)
429
+ arg0 = several_variants[0]
430
+ arg1 = several_variants[1]
456
431
 
457
- # View was found
458
- class ViewFoundError < UnexpectedMatchError
432
+ if arg1.nil?
433
+ exception_type = RuntimeError
434
+ message = arg0
435
+ else
436
+ exception_type = arg0
437
+ message = arg1
438
+ end
439
+
440
+ screenshot_embed if Wait.default_options[:screenshot_on_error]
441
+
442
+ raise exception_type, message
459
443
  end
460
444
 
461
- # View was not found
462
- class ViewNotFoundError < UnexpectedMatchError
445
+ # Raises an exception and always embeds a screenshot
446
+ #
447
+ # @raise [RuntimeError, StandardError] By default, raises a RuntimeError with
448
+ # `message`. You can pass in your own Exception class to override the
449
+ # the default behavior.
450
+ # @see Wait#fail
451
+ def screenshot_and_raise(*several_variants)
452
+ arg0 = several_variants[0]
453
+ arg1 = several_variants[1]
454
+
455
+ if arg1.nil?
456
+ exception_type = RuntimeError
457
+ message = arg0
458
+ else
459
+ exception_type = arg0
460
+ message = arg1
461
+ end
462
+
463
+ screenshot_embed
464
+
465
+ raise exception_type, message
463
466
  end
464
-
467
+
465
468
  # @!visibility private
466
- def self.parse_query_list(queries)
469
+ def parse_query_list(queries)
467
470
  unless queries.is_a?(Array)
468
471
  queries = [queries]
469
472
  end
@@ -481,6 +484,18 @@ module Calabash
481
484
  end
482
485
  end
483
486
 
487
+ # Query matched an unexpected set of views
488
+ class UnexpectedMatchError < RuntimeError
489
+ end
490
+
491
+ # View was found
492
+ class ViewFoundError < UnexpectedMatchError
493
+ end
494
+
495
+ # View was not found
496
+ class ViewNotFoundError < UnexpectedMatchError
497
+ end
498
+
484
499
  # @!visibility private
485
500
  class PrivateWaitTimeoutError < RuntimeError
486
501
  end