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