Module: Calabash::Cucumber::Core
- Includes:
- ConnectionHelpers, EnvironmentHelpers, FailureHelpers, Map, PlaybackHelpers, QueryHelpers, RotationHelpers, StatusBarHelpers, UIA
- Included in:
- DatePicker, Operations, WaitHelpers
- Defined in:
- lib/calabash-cucumber/core.rb
Constant Summary
PlaybackHelpers::DATA_PATH
Instance Method Summary
collapse
-
#backdoor(sel, arg) ⇒ Object
-
#calabash_exit ⇒ Object
-
#cell_swipe(options = {}) ⇒ Object
-
#client_version ⇒ Object
-
#console_attach ⇒ Object
-
#double_tap(uiquery, options = {}) ⇒ Object
-
#extract_query_and_options(uiquery, options) ⇒ Object
-
#flash(uiquery, *args) ⇒ Object
-
#flick(uiquery, delta, options = {}) ⇒ Object
-
#launcher ⇒ Object
-
#location_for_place(place) ⇒ Object
-
#locations_for_place(place) ⇒ Object
-
#macro(txt) ⇒ Object
-
#move_wheel(opts = {}) ⇒ Object
-
#pan(from, to, options = {}) ⇒ Object
-
#picker(opts = {:query => 'pickerView', :action => :texts}) ⇒ Object
-
#pinch(in_out, options = {}) ⇒ Object
-
#prepare_query_options(uiquery, options) ⇒ Object
-
#query(uiquery, *args) ⇒ Object
-
#query_action_with_options(action, uiquery, options) ⇒ Object
-
#query_all(uiquery, *args) ⇒ Object
-
#scroll(uiquery, direction) ⇒ Object
-
#scroll_to_cell(options = {:query => 'tableView', :row => 0, :section => 0, :scroll_position => :top, :animate => true}) ⇒ Object
-
#scroll_to_row(uiquery, number) ⇒ Object
-
#scroll_to_row_with_mark(row_id, options = {:query => 'tableView', :scroll_position => :middle, :animate => true}) ⇒ Object
-
#send_app_to_background(secs) ⇒ Object
-
#server_version ⇒ Object
-
#set_location(options) ⇒ Object
-
#shutdown_test_server ⇒ Object
-
#start_test_server_in_background(args = {}) ⇒ Object
args :app for device bundle id, for sim path to app.
-
#stop_test_server ⇒ Object
-
#swipe(dir, options = {}) ⇒ Object
-
#touch(uiquery, options = {}) ⇒ Object
-
#touch_hold(uiquery, options = {}) ⇒ Object
-
#two_finger_tap(uiquery, options = {}) ⇒ Object
#find_compatible_recording, #interpolate, #load_playback_data, #load_recording, #playback, #playback_file_directories, #record_begin, #record_end, #recording_name_for
#rotate, #rotate_home_button_to, #rotation_candidates
#device_orientation, #landscape?, #portrait?, #status_bar_orientation
Methods included from UIA
#escape_uia_string, #send_uia_command, #uia, #uia_call, #uia_call_method, #uia_double_tap, #uia_double_tap_mark, #uia_double_tap_offset, #uia_element_does_not_exist?, #uia_element_exists?, #uia_enter, #uia_flick_offset, #uia_handle_command, #uia_names, #uia_pan, #uia_pan_offset, #uia_pinch, #uia_pinch_offset, #uia_query, #uia_query_el, #uia_query_windows, #uia_screenshot, #uia_scroll_to, #uia_send_app_to_background, #uia_serialize_argument, #uia_serialize_arguments, #uia_serialize_command, #uia_set_location, #uia_swipe, #uia_swipe_offset, #uia_tap, #uia_tap_mark, #uia_tap_offset, #uia_touch_hold, #uia_touch_hold_offset, #uia_two_finger_tap, #uia_two_finger_tap_offset, #uia_type_string
Methods included from Map
#map, #raw_map
#fail, #screenshot, #screenshot_and_raise, #screenshot_embed
#escape_quotes, #point_from
#connection, #http
#_deprecated, #debug_logging?, #default_device, #device_family_iphone?, #full_console_logging?, #ios5?, #ios6?, #ios7?, #ipad?, #iphone?, #iphone_4in?, #iphone_5?, #iphone_app_emulated_on_ipad?, #ipod?, #no_deprecation_warnings?, #simulator?, #uia_available?, #uia_not_available?, #xamarin_test_cloud?
Instance Method Details
#backdoor(sel, arg) ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/calabash-cucumber/core.rb', line 272
def backdoor(sel, arg)
json = {
:selector => sel,
:arg => arg
}
res = http({:method => :post, :path => 'backdoor'}, json)
res = JSON.parse(res)
if res['outcome'] != 'SUCCESS'
screenshot_and_raise "backdoor #{json} failed because: #{res['reason']}\n#{res['details']}"
end
res['result']
end
|
#calabash_exit ⇒ Object
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/calabash-cucumber/core.rb', line 285
def calabash_exit
begin
http({:method => :post, :path => 'exit', :retryable_errors => Calabash::Cucumber::HTTPHelpers::RETRYABLE_ERRORS - [Errno::ECONNREFUSED, HTTPClient::KeepAliveDisconnected]})
rescue Errno::ECONNREFUSED, HTTPClient::KeepAliveDisconnected
[]
end
end
|
#cell_swipe(options = {}) ⇒ Object
104
105
106
107
108
109
|
# File 'lib/calabash-cucumber/core.rb', line 104
def cell_swipe(options={})
if uia_available?
raise 'cell_swipe not supported with instruments, simply use swipe with a query that matches the cell'
end
playback('cell_swipe', options)
end
|
#console_attach ⇒ Object
316
317
318
319
|
# File 'lib/calabash-cucumber/core.rb', line 316
def console_attach
@calabash_launcher = launcher.attach
end
|
#double_tap(uiquery, options = {}) ⇒ Object
66
67
68
|
# File 'lib/calabash-cucumber/core.rb', line 66
def double_tap(uiquery, options={})
query_action_with_options(:double_tap, uiquery, options)
end
|
#extract_query_and_options(uiquery, options) ⇒ Object
335
336
337
338
|
# File 'lib/calabash-cucumber/core.rb', line 335
def extract_query_and_options(uiquery, options)
options = prepare_query_options(uiquery, options)
return options[:query], options
end
|
#flash(uiquery, *args) ⇒ Object
42
43
44
|
# File 'lib/calabash-cucumber/core.rb', line 42
def flash(uiquery, *args)
map(uiquery, :flash, *args)
end
|
#flick(uiquery, delta, options = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/calabash-cucumber/core.rb', line 74
def flick(uiquery, delta, options={})
uiquery, options = extract_query_and_options(uiquery, options)
options[:delta] = delta
views_touched = launcher.actions.flick(options)
unless uiquery.nil?
screenshot_and_raise "flick could not find view: '#{uiquery}', args: #{options}" if views_touched.empty?
end
views_touched
end
|
#location_for_place(place) ⇒ Object
210
211
212
213
214
|
# File 'lib/calabash-cucumber/core.rb', line 210
def location_for_place(place)
search_results = locations_for_place(place)
raise "Got no results for #{place}" if search_results.empty?
search_results.first
end
|
#locations_for_place(place) ⇒ Object
216
217
218
|
# File 'lib/calabash-cucumber/core.rb', line 216
def locations_for_place(place)
Geocoder.search(place)
end
|
#macro(txt) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/calabash-cucumber/core.rb', line 30
def macro(txt)
if self.respond_to? :step
step(txt)
else
Then txt
end
end
|
#move_wheel(opts = {}) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/calabash-cucumber/core.rb', line 220
def move_wheel(opts={})
q = opts[:query] || 'pickerView'
wheel = opts[:wheel] || 0
dir = opts[:dir] || :down
raise 'Wheel index must be non negative' if wheel < 0
raise "Only up and down supported :dir (#{dir})" unless [:up, :down].include?(dir)
if ENV['OS'] == 'ios4'
playback "wheel_#{dir}", :query => "#{q} pickerTable index:#{wheel}"
elsif ios7?
raise NotImplementedError
else
playback "wheel_#{dir}", :query => "#{q} pickerTableView index:#{wheel}"
end
end
|
#pan(from, to, options = {}) ⇒ Object
95
96
97
|
# File 'lib/calabash-cucumber/core.rb', line 95
def pan(from, to, options={})
launcher.actions.pan(from, to, options)
end
|
#picker(opts = {:query => 'pickerView', :action => :texts}) ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/calabash-cucumber/core.rb', line 238
def picker(opts={:query => 'pickerView', :action => :texts})
raise 'Not implemented' unless opts[:action] == :texts
q = opts[:query]
check_element_exists(q)
comps = query(q, :numberOfComponents).first
row_counts = []
texts = []
comps.times do |i|
row_counts[i] = query(q, :numberOfRowsInComponent => i).first
texts[i] = []
end
row_counts.each_with_index do |row_count, comp|
row_count.times do |i|
spec = [{:viewForRow => i}, {:forComponent => comp}]
view = query(q, spec).first
if view
txt = query(q, spec, :accessibilityLabel).first
else
txt = query(q, :delegate, [{:pickerView => :view},
{:titleForRow => i},
{:forComponent => comp}]).first
end
texts[comp] << txt
end
end
texts
end
|
#pinch(in_out, options = {}) ⇒ Object
99
100
101
|
# File 'lib/calabash-cucumber/core.rb', line 99
def pinch(in_out, options={})
launcher.actions.pinch(in_out.to_sym,options)
end
|
#prepare_query_options(uiquery, options) ⇒ Object
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
# File 'lib/calabash-cucumber/core.rb', line 340
def prepare_query_options(uiquery, options)
opts = options.dup
if uiquery.is_a?(Array)
raise 'No elements in array' if uiquery.empty?
uiquery = uiquery.first
end
if uiquery.is_a?(Hash)
opts[:offset] = point_from(uiquery, options)
uiquery = nil
end
opts[:query] = uiquery
opts
end
|
#query(uiquery, *args) ⇒ Object
38
39
40
|
# File 'lib/calabash-cucumber/core.rb', line 38
def query(uiquery, *args)
map(uiquery, :query, *args)
end
|
#query_action_with_options(action, uiquery, options) ⇒ Object
326
327
328
329
330
331
332
333
|
# File 'lib/calabash-cucumber/core.rb', line 326
def query_action_with_options(action, uiquery, options)
uiquery, options = extract_query_and_options(uiquery, options)
views_touched = launcher.actions.send(action, options)
unless uiquery.nil?
screenshot_and_raise "#{action} could not find view: '#{uiquery}', args: #{options}" if views_touched.empty?
end
views_touched
end
|
#query_all(uiquery, *args) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/calabash-cucumber/core.rb', line 54
def query_all(uiquery, *args)
msg0 = "use the 'all' or 'visible' query language feature"
msg1 = 'see: https://github.com/calabash/calabash-ios/wiki/05-Query-syntax'
msg = "#{msg0}\n#{msg1}"
_deprecated('0.9.133', msg, :warn)
map("all #{uiquery}", :query, *args)
end
|
111
112
113
114
115
|
# File 'lib/calabash-cucumber/core.rb', line 111
def scroll(uiquery, direction)
views_touched=map(uiquery, :scroll, direction)
screenshot_and_raise "could not find view to scroll: '#{uiquery}', args: #{direction}" if views_touched.empty?
views_touched
end
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/calabash-cucumber/core.rb', line 125
def scroll_to_cell(options={:query => 'tableView',
:row => 0,
:section => 0,
:scroll_position => :top,
:animate => true})
uiquery = options[:query] || 'tableView'
row = options[:row]
sec = options[:section]
if row.nil? or sec.nil?
raise 'You must supply both :row and :section keys to scroll_to_cell'
end
args = []
if options.has_key?(:scroll_position)
args << options[:scroll_position]
else
args << 'top'
end
if options.has_key?(:animate)
args << options[:animate]
end
views_touched=map(uiquery, :scrollToRow, row.to_i, sec.to_i, *args)
if views_touched.empty? or views_touched.member? '<VOID>'
screenshot_and_raise "Unable to scroll: '#{uiquery}' to: #{options}"
end
views_touched
end
|
117
118
119
120
121
122
123
|
# File 'lib/calabash-cucumber/core.rb', line 117
def scroll_to_row(uiquery, number)
views_touched=map(uiquery, :scrollToRow, number)
if views_touched.empty? or views_touched.member? '<VOID>'
screenshot_and_raise "Unable to scroll: '#{uiquery}' to: #{number}"
end
views_touched
end
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/calabash-cucumber/core.rb', line 155
def scroll_to_row_with_mark(row_id, options={:query => 'tableView',
:scroll_position => :middle,
:animate => true})
uiquery = options[:query] || 'tableView'
args = []
if options.has_key?(:scroll_position)
args << options[:scroll_position]
else
args << 'middle'
end
if options.has_key?(:animate)
args << options[:animate]
end
views_touched=map(uiquery, :scrollToRowWithMark, row_id, *args)
if views_touched.empty? or views_touched.member? '<VOID>'
msg = options[:failed_message] || "Unable to scroll: '#{uiquery}' to: #{options}"
screenshot_and_raise msg
end
views_touched
end
|
#send_app_to_background(secs) ⇒ Object
179
180
181
|
# File 'lib/calabash-cucumber/core.rb', line 179
def send_app_to_background(secs)
launcher.actions.send_app_to_background(secs)
end
|
#server_version ⇒ Object
46
47
48
|
# File 'lib/calabash-cucumber/core.rb', line 46
def server_version
JSON.parse(http(:path => 'version'))
end
|
#set_location(options) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/calabash-cucumber/core.rb', line 183
def set_location(options)
if uia_available?
uia_set_location(options)
else
if options[:place]
res = location_for_place(options[:place])
lat = res.latitude
lon = res.longitude
else
lat = options[:latitude]
lon = options[:longitude]
end
body_data = {:action => :change_location,
:latitude => lat,
:longitude => lon}
body = http({:method => :post, :path => 'location'}, body_data)
res = JSON.parse(body)
if res['outcome'] != 'SUCCESS'
screenshot_and_raise "Set location change failed, for #{lat}, #{lon} (#{body})."
end
res['results']
end
end
|
#shutdown_test_server ⇒ Object
310
311
312
313
|
# File 'lib/calabash-cucumber/core.rb', line 310
def shutdown_test_server
stop_test_server
end
|
#start_test_server_in_background(args = {}) ⇒ Object
args :app for device bundle id, for sim path to app
298
299
300
301
302
303
|
# File 'lib/calabash-cucumber/core.rb', line 298
def start_test_server_in_background(args={})
stop_test_server
@calabash_launcher = Calabash::Cucumber::Launcher.new()
@calabash_launcher.relaunch(args)
@calabash_launcher
end
|
#stop_test_server ⇒ Object
#swipe(dir, options = {}) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/calabash-cucumber/core.rb', line 88
def swipe(dir, options={})
unless uia_available?
options = options.merge(:status_bar_orientation => status_bar_orientation)
end
launcher.actions.swipe(dir.to_sym, options)
end
|
#touch(uiquery, options = {}) ⇒ Object
62
63
64
|
# File 'lib/calabash-cucumber/core.rb', line 62
def touch(uiquery, options={})
query_action_with_options(:touch, uiquery, options)
end
|
#touch_hold(uiquery, options = {}) ⇒ Object
84
85
86
|
# File 'lib/calabash-cucumber/core.rb', line 84
def touch_hold(uiquery, options={})
query_action_with_options(:touch_hold, uiquery, options)
end
|
#two_finger_tap(uiquery, options = {}) ⇒ Object
70
71
72
|
# File 'lib/calabash-cucumber/core.rb', line 70
def two_finger_tap(uiquery,options={})
query_action_with_options(:two_finger_tap, uiquery, options)
end
|