Module: Calabash::Cucumber::UIA
Constant Summary
Constants included
from Logging
Logging::CALABASH_NO_DEPRECATION
Instance Method Summary
collapse
-
#escape_uia_string(string) ⇒ Object
-
#send_uia_command(opts = {}) ⇒ Object
DEPRECATED: Use uia("...javascript..", options)
instead.
-
#uia(command, options = {}) ⇒ Object
-
#uia_call(args_arr, *opts) ⇒ Object
-
#uia_call_method(cmd, args_arr, *opts) ⇒ Object
-
#uia_call_windows(args_arr, *opts) ⇒ Object
-
#uia_double_tap(*queryparts) ⇒ Object
-
#uia_double_tap_mark(mark) ⇒ Object
-
#uia_double_tap_offset(offset) ⇒ Object
-
#uia_element_does_not_exist?(*queryparts) ⇒ Boolean
-
#uia_element_exists?(*queryparts) ⇒ Boolean
-
#uia_enter ⇒ Object
-
#uia_flick_offset(from, to) ⇒ Object
-
#uia_handle_command(cmd, *query_args) ⇒ Object
-
#uia_names(*queryparts) ⇒ Object
-
#uia_pan(from_q, to_q) ⇒ Object
-
#uia_pan_offset(from, to, options) ⇒ Object
-
#uia_pinch(*queryparts) ⇒ Object
-
#uia_pinch_offset(in_or_out, offset, duration) ⇒ Object
-
#uia_query(*queryparts) ⇒ Object
-
#uia_query_el(*queryparts) ⇒ Object
-
#uia_query_windows(*queryparts) ⇒ Object
-
#uia_screenshot(name) ⇒ Object
-
#uia_scroll_to(*queryparts) ⇒ Object
-
#uia_send_app_to_background(secs) ⇒ Object
-
#uia_serialize_argument(part) ⇒ Object
-
#uia_serialize_arguments(args) ⇒ Object
-
#uia_serialize_command(cmd, *query_args) ⇒ Object
-
#uia_set_location(options) ⇒ Object
-
#uia_swipe(*queryparts) ⇒ Object
-
#uia_swipe_offset(offset, options) ⇒ Object
-
#uia_tap(*queryparts) ⇒ Object
-
#uia_tap_mark(mark) ⇒ Object
-
#uia_tap_offset(offset) ⇒ Object
-
#uia_touch_hold(duration, *queryparts) ⇒ Object
-
#uia_touch_hold_offset(duration, offset) ⇒ Object
-
#uia_two_finger_tap(*queryparts) ⇒ Object
-
#uia_two_finger_tap_offset(offset) ⇒ Object
-
#uia_type_string(string, opt_text_before = '', escape = true) ⇒ Object
-
#uia_wait_tap(query, options = {}) ⇒ Object
Methods included from Logging
#_deprecated, #calabash_info, #calabash_warn, #debug_logging?, #full_console_logging?, #no_deprecation_warnings?
Instance Method Details
#escape_uia_string(string) ⇒ Object
245
246
247
248
|
# File 'lib/calabash-cucumber/uia.rb', line 245
def escape_uia_string(string)
escape_quotes string
end
|
#send_uia_command(opts = {}) ⇒ Object
DEPRECATED: Use uia("...javascript..", options)
instead. deprecated because the method signature is poor
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/calabash-cucumber/uia.rb', line 252
def send_uia_command(opts ={})
uia(opts[:command], opts)
end
|
#uia(command, options = {}) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/calabash-cucumber/uia.rb', line 13
def uia(command,options={})
res = http({:method => :post, :path => 'uia'}, {:command => command}.merge(options))
res = JSON.parse(res)
if res['outcome'] != 'SUCCESS'
raise "uia action failed because: #{res['reason']}\n#{res['details']}"
end
res['results'].first
end
|
#uia_call(args_arr, *opts) ⇒ Object
171
172
173
|
# File 'lib/calabash-cucumber/uia.rb', line 171
def uia_call(args_arr, *opts)
uia_call_method(:queryEl, args_arr, *opts)
end
|
#uia_call_method(cmd, args_arr, *opts) ⇒ Object
179
180
181
182
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
209
210
211
212
213
214
|
# File 'lib/calabash-cucumber/uia.rb', line 179
def uia_call_method(cmd, args_arr, *opts)
if opts.empty?
return uia_handle_command(cmd, args_arr)
end
js_cmd = uia_serialize_command(cmd, args_arr)
js_args = []
opts.each do |invocation|
js_args << case invocation
when Symbol
"#{invocation}()"
when Hash
m = invocation.keys.first
args = invocation[m]
if args.is_a?(Array)
serialized_args = (args.map &:to_json).join(',')
else
serialized_args = args.to_json
end
"#{m}(#{serialized_args})"
else
raise "Invalid invocation spec #{invocation}"
end
end
command = "#{js_cmd}.#{js_args.join('.')}"
if debug_logging?
puts 'Sending UIA command'
puts command
end
uia_result(uia(command))
end
|
#uia_call_windows(args_arr, *opts) ⇒ Object
175
176
177
|
# File 'lib/calabash-cucumber/uia.rb', line 175
def uia_call_windows(args_arr, *opts)
uia_call_method(:queryElWindows, args_arr, *opts)
end
|
#uia_double_tap(*queryparts) ⇒ Object
63
64
65
|
# File 'lib/calabash-cucumber/uia.rb', line 63
def uia_double_tap(*queryparts)
uia_handle_command(:doubleTap, queryparts)
end
|
#uia_double_tap_mark(mark) ⇒ Object
67
68
69
|
# File 'lib/calabash-cucumber/uia.rb', line 67
def uia_double_tap_mark(mark)
uia_double_tap(:view, {:marked => mark})
end
|
#uia_double_tap_offset(offset) ⇒ Object
71
72
73
|
# File 'lib/calabash-cucumber/uia.rb', line 71
def uia_double_tap_offset(offset)
uia_handle_command(:doubleTapOffset, offset)
end
|
#uia_element_does_not_exist?(*queryparts) ⇒ Boolean
127
128
129
|
# File 'lib/calabash-cucumber/uia.rb', line 127
def uia_element_does_not_exist?(*queryparts)
uia_handle_command(:elementDoesNotExist, queryparts)
end
|
#uia_element_exists?(*queryparts) ⇒ Boolean
123
124
125
|
# File 'lib/calabash-cucumber/uia.rb', line 123
def uia_element_exists?(*queryparts)
uia_handle_command(:elementExists, queryparts)
end
|
#uia_enter ⇒ Object
149
150
151
|
# File 'lib/calabash-cucumber/uia.rb', line 149
def uia_enter
uia_handle_command(:enter)
end
|
#uia_flick_offset(from, to) ⇒ Object
83
84
85
|
# File 'lib/calabash-cucumber/uia.rb', line 83
def uia_flick_offset(from, to)
uia_handle_command(:flickOffset, from, to)
end
|
#uia_handle_command(cmd, *query_args) ⇒ Object
216
217
218
219
220
221
222
223
224
|
# File 'lib/calabash-cucumber/uia.rb', line 216
def uia_handle_command(cmd, *query_args)
command = uia_serialize_command(cmd, *query_args)
if debug_logging?
puts 'Sending UIA command'
puts command
end
s = uia(command)
uia_result(s)
end
|
#uia_names(*queryparts) ⇒ Object
46
47
48
49
|
# File 'lib/calabash-cucumber/uia.rb', line 46
def uia_names(*queryparts)
uia_handle_command(:names, queryparts)
end
|
#uia_pan(from_q, to_q) ⇒ Object
95
96
97
|
# File 'lib/calabash-cucumber/uia.rb', line 95
def uia_pan(from_q, to_q)
uia_handle_command(:pan, from_q, to_q)
end
|
#uia_pan_offset(from, to, options) ⇒ Object
99
100
101
|
# File 'lib/calabash-cucumber/uia.rb', line 99
def uia_pan_offset(from, to, options)
uia_handle_command(:panOffset, from, to, options)
end
|
#uia_pinch(*queryparts) ⇒ Object
111
112
113
|
# File 'lib/calabash-cucumber/uia.rb', line 111
def uia_pinch(*queryparts)
uia_handle_command(:pinch, queryparts)
end
|
#uia_pinch_offset(in_or_out, offset, duration) ⇒ Object
115
116
117
|
# File 'lib/calabash-cucumber/uia.rb', line 115
def uia_pinch_offset(in_or_out, offset, duration)
uia_handle_command(:pinchOffset, in_or_out, offset, duration)
end
|
#uia_query(*queryparts) ⇒ Object
31
32
33
34
|
# File 'lib/calabash-cucumber/uia.rb', line 31
def uia_query(*queryparts)
uia_handle_command(:query, queryparts)
end
|
#uia_query_el(*queryparts) ⇒ Object
36
37
38
39
|
# File 'lib/calabash-cucumber/uia.rb', line 36
def uia_query_el(*queryparts)
uia_handle_command(:queryEl, queryparts)
end
|
#uia_query_windows(*queryparts) ⇒ Object
41
42
43
44
|
# File 'lib/calabash-cucumber/uia.rb', line 41
def uia_query_windows(*queryparts)
uia_handle_command(:queryWindows, queryparts)
end
|
#uia_screenshot(name) ⇒ Object
131
132
133
|
# File 'lib/calabash-cucumber/uia.rb', line 131
def uia_screenshot(name)
uia_handle_command(:screenshot, name)
end
|
119
120
121
|
# File 'lib/calabash-cucumber/uia.rb', line 119
def uia_scroll_to(*queryparts)
uia_handle_command(:scrollTo, queryparts)
end
|
#uia_send_app_to_background(secs) ⇒ Object
167
168
169
|
# File 'lib/calabash-cucumber/uia.rb', line 167
def uia_send_app_to_background(secs)
uia_handle_command(:deactivate, secs)
end
|
#uia_serialize_argument(part) ⇒ Object
237
238
239
240
241
242
243
|
# File 'lib/calabash-cucumber/uia.rb', line 237
def uia_serialize_argument(part)
if part.is_a?(String)
"'#{escape_uia_string(part)}'"
else
"'#{escape_uia_string(part.to_edn)}'"
end
end
|
#uia_serialize_arguments(args) ⇒ Object
231
232
233
234
235
|
# File 'lib/calabash-cucumber/uia.rb', line 231
def uia_serialize_arguments(args)
args.map do |part|
uia_serialize_argument(part)
end
end
|
#uia_serialize_command(cmd, *query_args) ⇒ Object
226
227
228
229
|
# File 'lib/calabash-cucumber/uia.rb', line 226
def uia_serialize_command(cmd, *query_args)
args = uia_serialize_arguments(query_args)
%Q[uia.#{cmd}(#{args.join(', ')})]
end
|
#uia_set_location(options) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/calabash-cucumber/uia.rb', line 153
def uia_set_location(options)
validate_hash_is_location!(options)
if options[:place]
place = options[:place]
search_results = Geocoder.search(place)
raise "Got no results for #{place}" if search_results.empty?
loc = search_results.first
loc_data = {'latitude'=>loc.latitude, 'longitude'=>loc.longitude}
elsif options.is_a?(Hash)
loc_data = options
end
uia_handle_command(:setLocation, loc_data)
end
|
#uia_swipe(*queryparts) ⇒ Object
103
104
105
|
# File 'lib/calabash-cucumber/uia.rb', line 103
def uia_swipe(*queryparts)
uia_handle_command(:swipe, queryparts)
end
|
#uia_swipe_offset(offset, options) ⇒ Object
107
108
109
|
# File 'lib/calabash-cucumber/uia.rb', line 107
def uia_swipe_offset(offset, options)
uia_handle_command(:swipeOffset, offset, options)
end
|
#uia_tap(*queryparts) ⇒ Object
51
52
53
|
# File 'lib/calabash-cucumber/uia.rb', line 51
def uia_tap(*queryparts)
uia_handle_command(:tap, queryparts)
end
|
#uia_tap_mark(mark) ⇒ Object
55
56
57
|
# File 'lib/calabash-cucumber/uia.rb', line 55
def uia_tap_mark(mark)
uia_handle_command(:tapMark, mark)
end
|
#uia_tap_offset(offset) ⇒ Object
59
60
61
|
# File 'lib/calabash-cucumber/uia.rb', line 59
def uia_tap_offset(offset)
uia_handle_command(:tapOffset, offset)
end
|
#uia_touch_hold(duration, *queryparts) ⇒ Object
87
88
89
|
# File 'lib/calabash-cucumber/uia.rb', line 87
def uia_touch_hold(duration, *queryparts)
uia_handle_command(:touchHold, duration, queryparts)
end
|
#uia_touch_hold_offset(duration, offset) ⇒ Object
91
92
93
|
# File 'lib/calabash-cucumber/uia.rb', line 91
def uia_touch_hold_offset(duration, offset)
uia_handle_command(:touchHoldOffset, duration, offset)
end
|
#uia_two_finger_tap(*queryparts) ⇒ Object
75
76
77
|
# File 'lib/calabash-cucumber/uia.rb', line 75
def uia_two_finger_tap(*queryparts)
uia_handle_command(:twoFingerTap, queryparts)
end
|
#uia_two_finger_tap_offset(offset) ⇒ Object
79
80
81
|
# File 'lib/calabash-cucumber/uia.rb', line 79
def uia_two_finger_tap_offset(offset)
uia_handle_command(:twoFingerTapOffset, offset)
end
|
#uia_type_string(string, opt_text_before = '', escape = true) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/calabash-cucumber/uia.rb', line 135
def uia_type_string(string, opt_text_before='', escape=true)
if escape && string.index(/\\/)
indexes = string.enum_for(:scan,/\\/).map { Regexp.last_match.begin(0) }
indexes.reverse.each { |idx| string = string.insert(idx, '\\') }
end
res = uia_handle_command(:typeString, string, opt_text_before)
status = res['status']
if status.eql?('error')
value = res['value']
raise "could not type '#{string}' - '#{value}'"
end
status
end
|
#uia_wait_tap(query, options = {}) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/calabash-cucumber/uia.rb', line 22
def uia_wait_tap(query, options={})
res = http({:method => :post, :path => 'uia-tap'}, {:query => query}.merge(options))
res = JSON.parse(res)
if res['outcome'] != 'SUCCESS'
raise "uia-tap action failed because: #{res['reason']}\n#{res['details']}"
end
res['results'].first
end
|