Module: Calabash::Android::Operations
Defined Under Namespace
Classes: Device
Constant Summary
MonkeyHelpers::MAX_RETRIES
Constants included
from WaitHelpers
WaitHelpers::DEFAULT_OPTS
Class Method Summary
collapse
Instance Method Summary
collapse
-
#app_to_background(secs) ⇒ Object
-
#backdoor(method_name, arguments = [], options = {}) ⇒ Object
-
#cell_swipe(options = {}) ⇒ Object
-
#check_element_does_not_exist(query) ⇒ Object
-
#check_element_exists(query) ⇒ Object
-
#check_view_with_mark_exists(expected_mark) ⇒ Object
-
#classes(query_string, *args) ⇒ Object
-
#clear_app_data ⇒ Object
-
#clear_preferences(name) ⇒ Object
-
#client_version ⇒ Object
-
#connect_to_test_server ⇒ Object
-
#current_activity ⇒ Object
-
#default_device ⇒ Object
-
#deprecated_actions ⇒ Object
-
#disconnect_from_test_server ⇒ Object
-
#done ⇒ Object
-
#each_item(opts = {:query => "android.widget.ListView", :post_scroll => 0.2}, &block) ⇒ Object
-
#element_does_not_exist(uiquery) ⇒ Object
-
#element_exists(uiquery) ⇒ Object
-
#element_is_not_hidden(uiquery) ⇒ Object
a better name would be element_exists_and_is_not_hidden.
-
#evaluate_javascript(query_string, javascript, opt = {}) ⇒ Object
-
#execute_uiquery(uiquery) ⇒ Object
-
#fail(msg = "Error. Check log for details.", options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
-
#find_scrollable_view(options = {}) ⇒ Object
-
#flash(query_string) ⇒ Object
-
#get_activity_orientation ⇒ Object
Note: Android 2.2 will always return either portrait or landscape, not reverse_portrait or reverse_landscape.
-
#get_preferences(name) ⇒ Object
-
#hide_soft_keyboard ⇒ Object
-
#html(q) ⇒ Object
-
#http(path, data = {}, options = {}) ⇒ Object
-
#http_put(path, data = {}, options = {}) ⇒ Object
-
#install_app(app_path) ⇒ Object
-
#interpolate(recording, options = {}) ⇒ Object
-
#label(uiquery) ⇒ Object
-
#load_dylib(file_path, classes = []) ⇒ Object
-
#load_playback_data(recording, options = {}) ⇒ Object
-
#log(message) ⇒ Object
-
#macro(txt) ⇒ Object
-
#make_http_request(options) ⇒ Object
-
#map(query, method_name, *method_args) ⇒ Object
-
#ni ⇒ Object
-
#page(clz, *args) ⇒ Object
simple page object helper.
-
#perform_action(action, *arguments) ⇒ Object
-
#performAction(action, *arguments) ⇒ Object
-
#playback(recording, options = {}) ⇒ Object
-
#press_back_button ⇒ Object
-
#press_button(key) ⇒ Object
-
#press_down_button ⇒ Object
-
#press_enter_button ⇒ Object
-
#press_left_button ⇒ Object
-
#press_menu_button ⇒ Object
-
#press_right_button ⇒ Object
-
#press_up_button ⇒ Object
-
#press_user_action_button(action_name = nil) ⇒ Object
-
#pull(remote, local) ⇒ Object
-
#push(local, remote) ⇒ Object
-
#query(uiquery, *args) ⇒ Object
-
#record_begin ⇒ Object
-
#record_end(file_name) ⇒ Object
-
#reinstall_apps ⇒ Object
-
#reinstall_test_server ⇒ Object
-
#removed_actions ⇒ Object
-
#rotate(dir) ⇒ Object
-
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object
-
#screenshot_and_raise(e, options = nil) ⇒ Object
-
#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
-
#scroll(query_string, direction) ⇒ Object
-
#scroll_down(options = {}) ⇒ Object
-
#scroll_to(query_string, options = {}) ⇒ Object
-
#scroll_to_row(uiquery, number) ⇒ Object
-
#scroll_up(options = {}) ⇒ Object
-
#select_context_menu_item(view_uiquery, menu_item_query_string) ⇒ Object
-
#select_item_from_spinner(item_query_string, options = {}) ⇒ Object
-
#select_options_menu_item(identifier, options = {}) ⇒ Object
-
#server_version ⇒ Object
-
#set_activity_orientation(orientation) ⇒ Object
-
#set_date(query_string, year_or_datestring, month = nil, day = nil) ⇒ Object
-
#set_default_device(device) ⇒ Object
-
#set_gps_coordinates(latitude, longitude) ⇒ Object
-
#set_gps_coordinates_from_location(location) ⇒ Object
-
#set_preferences(name, hash) ⇒ Object
-
#set_text(uiquery, txt) ⇒ Object
-
#set_time(query_string, hour_or_timestring, minute = nil) ⇒ Object
-
#shutdown_test_server ⇒ Object
-
#start_test_server_in_background(options = {}, &block) ⇒ Object
-
#step_deprecated ⇒ Object
-
#swipe(query_string, options = {}) ⇒ Object
-
#uninstall_apps ⇒ Object
-
#update_app(app_path) ⇒ Object
-
#upload_file(file_path) ⇒ String
The path of the uploaded file on the device.
-
#url_for(method) ⇒ Object
-
#view_with_mark_exists(expected_mark) ⇒ Object
-
#wake_up ⇒ Object
#drag_and_drop, #drag_coordinates
#adb_command, #existing_monkey_pids, #get_monkey_port, #kill_existing_monkey_processes, #kill_monkey_processes_on_device, #kill_monkey_processes_on_host, #monkey_move_from, #monkey_tap, #monkey_touch, #start_monkey
#xamarin_test_cloud?
#handle_error_with_options, #screenshot_and_retry, #until_element_does_not_exist, #until_element_exists, #wait_error, #wait_for, #wait_for_activity, #wait_for_element_does_not_exist, #wait_for_element_exists, #wait_for_elements_do_not_exist, #wait_for_elements_exist, #wait_for_text, #wait_for_text_to_disappear, #wait_poll, #when_element_exists
#double_tap, #drag, #execute_gesture, #find_coordinate, #flick, #flick_down, #flick_left, #flick_right, #flick_up, #long_press, #long_press_when_element_exists, #pan, #pan_down, #pan_left, #pan_right, #pan_up, #pinch, #pinch_in, #pinch_out, #query_result?, #tap, #tap_mark, #tap_when_element_exists, #touch
#assert_text, #clear_text, #clear_text_in, #enter_text, #escape_quotes, #has_text?, #keyboard_enter_char, #keyboard_enter_text, #keyboard_visible?, #set_selection, #wait_for_keyboard
Class Method Details
.extended(base) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/calabash-android/operations.rb', line 41
def self.extended(base)
if (class << base; included_modules.map(&:to_s).include?('Cucumber::RbSupport::RbWorld'); end)
unless instance_methods.include?(:embed)
original_embed = base.method(:embed)
define_method(:embed) do |*args|
original_embed.call(*args)
end
end
end
end
|
Instance Method Details
#app_to_background(secs) ⇒ Object
1217
1218
1219
|
# File 'lib/calabash-android/operations.rb', line 1217
def app_to_background(secs)
ni
end
|
#backdoor(method_name, arguments = [], options = {}) ⇒ Object
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
|
# File 'lib/calabash-android/operations.rb', line 1287
def backdoor(method_name, arguments = [], options={})
arguments = [arguments] unless arguments.is_a?(Array)
result = JSON.parse(http('/backdoor', {method_name: method_name, arguments: arguments}))
if result['outcome'] != 'SUCCESS'
raise result.to_s
end
result['result']
end
|
#cell_swipe(options = {}) ⇒ Object
1074
1075
1076
|
# File 'lib/calabash-android/operations.rb', line 1074
def cell_swipe(options={})
ni
end
|
#check_element_does_not_exist(query) ⇒ Object
1239
1240
1241
1242
1243
|
# File 'lib/calabash-android/operations.rb', line 1239
def check_element_does_not_exist( query )
if element_exists( query )
screenshot_and_raise "Expected no elements to match query: #{query}"
end
end
|
#check_element_exists(query) ⇒ Object
1233
1234
1235
1236
1237
|
# File 'lib/calabash-android/operations.rb', line 1233
def check_element_exists( query )
if not element_exists( query )
screenshot_and_raise "No element found for query: #{query}"
end
end
|
#check_view_with_mark_exists(expected_mark) ⇒ Object
1245
1246
1247
|
# File 'lib/calabash-android/operations.rb', line 1245
def check_view_with_mark_exists(expected_mark)
check_element_exists( "view marked:'#{expected_mark}'" )
end
|
#classes(query_string, *args) ⇒ Object
272
273
274
|
# File 'lib/calabash-android/operations.rb', line 272
def classes(query_string, *args)
query(query_string, :class, *args)
end
|
#clear_app_data ⇒ Object
130
131
132
|
# File 'lib/calabash-android/operations.rb', line 130
def clear_app_data
default_device.clear_app_data
end
|
#clear_preferences(name) ⇒ Object
187
188
189
|
# File 'lib/calabash-android/operations.rb', line 187
def clear_preferences(name)
default_device.clear_preferences(name)
end
|
#client_version ⇒ Object
159
160
161
|
# File 'lib/calabash-android/operations.rb', line 159
def client_version
default_device.client_version
end
|
#connect_to_test_server ⇒ Object
291
292
293
294
295
|
# File 'lib/calabash-android/operations.rb', line 291
def connect_to_test_server
puts "Explicit calls to connect_to_test_server should be removed."
puts "Please take a look in your hooks file for calls to this methods."
puts "(Hooks are stored in features/support)"
end
|
#current_activity ⇒ Object
52
53
54
|
# File 'lib/calabash-android/operations.rb', line 52
def current_activity
`#{default_device.adb_command} shell dumpsys window windows`.force_encoding('UTF-8').each_line.grep(/mFocusedApp.+[\.\/]([^.\s\/\}]+)/){$1}.first
end
|
#default_device ⇒ Object
68
69
70
|
# File 'lib/calabash-android/operations.rb', line 68
def default_device
@@default_device ||= Device.new(self, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
end
|
#deprecated_actions ⇒ Object
99
100
101
102
103
|
# File 'lib/calabash-android/operations.rb', line 99
def deprecated_actions
@deprecated_actions ||= Hash[
*File.readlines(File.join(File.dirname(__FILE__), 'deprecated_actions.map')).map{|e| e.chomp.split(',', 2)}.flatten
]
end
|
#disconnect_from_test_server ⇒ Object
297
298
299
300
301
|
# File 'lib/calabash-android/operations.rb', line 297
def disconnect_from_test_server
puts "Explicit calls to disconnect_from_test_server should be removed."
puts "Please take a look in your hooks file for calls to this methods."
puts "(Hooks are stored in features/support)"
end
|
#done ⇒ Object
1078
1079
1080
|
# File 'lib/calabash-android/operations.rb', line 1078
def done
ni
end
|
#each_item(opts = {:query => "android.widget.ListView", :post_scroll => 0.2}, &block) ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/calabash-android/operations.rb', line 231
def each_item(opts={:query => "android.widget.ListView", :post_scroll => 0.2}, &block)
uiquery = opts[:query] || "android.widget.ListView"
skip_if = opts[:skip_if] || lambda { |i| false }
stop_when = opts[:stop_when] || lambda { |i| false }
check_element_exists(uiquery)
num_items = query(opts[:query], :adapter, :count).first
num_items.times do |item|
next if skip_if.call(item)
break if stop_when.call(item)
scroll_to_row(opts[:query], item)
sleep(opts[:post_scroll]) if opts[:post_scroll] and opts[:post_scroll] > 0
yield(item)
end
end
|
#element_does_not_exist(uiquery) ⇒ Object
1221
1222
1223
|
# File 'lib/calabash-android/operations.rb', line 1221
def element_does_not_exist(uiquery)
query(uiquery).empty?
end
|
#element_exists(uiquery) ⇒ Object
1225
1226
1227
|
# File 'lib/calabash-android/operations.rb', line 1225
def element_exists(uiquery)
not element_does_not_exist(uiquery)
end
|
#element_is_not_hidden(uiquery) ⇒ Object
a better name would be element_exists_and_is_not_hidden
1250
1251
1252
|
# File 'lib/calabash-android/operations.rb', line 1250
def element_is_not_hidden(uiquery)
ni
end
|
#evaluate_javascript(query_string, javascript, opt = {}) ⇒ Object
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
|
# File 'lib/calabash-android/operations.rb', line 1275
def evaluate_javascript(query_string, javascript, opt={})
wait_for_elements_exist(query_string, {timeout: Calabash::Android::Defaults.query_timeout})
result = JSON.parse(http("/map", {query: query_string, operation: {method_name: 'execute-javascript'}, javascript: javascript}))
if result['outcome'] != 'SUCCESS' || result['results'].nil?
parsed_result = result['results'].map {|r| "\"#{r}\","}.join("\n")
raise "Could not evaluate javascript: \n#{parsed_result}"
end
result['results']
end
|
#execute_uiquery(uiquery) ⇒ Object
922
923
924
925
926
927
928
929
930
931
932
933
934
935
|
# File 'lib/calabash-android/operations.rb', line 922
def execute_uiquery(uiquery)
if uiquery.instance_of? String
elements = query(uiquery)
return elements.first unless elements.empty?
else
elements = uiquery
return elements.first if elements.instance_of?(Array)
return elements if elements.instance_of?(Hash)
end
nil
end
|
#fail(msg = "Error. Check log for details.", options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
167
168
169
|
# File 'lib/calabash-android/operations.rb', line 167
def fail(msg="Error. Check log for details.", options={:prefix => nil, :name => nil, :label => nil})
screenshot_and_raise(msg, options)
end
|
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
|
# File 'lib/calabash-android/operations.rb', line 1082
def find_scrollable_view(options={})
timeout = options[:timeout] || 30
begin
Timeout.timeout(timeout, WaitError) do
scroll_view_query_string = "android.widget.ScrollView index:0"
list_view_query_string = "android.widget.AbsListView index:0"
web_view_query_string = "android.webkit.WebView index:0"
loop do
if element_exists(scroll_view_query_string)
return scroll_view_query_string
elsif element_exists(list_view_query_string)
return list_view_query_string
elsif element_exists(web_view_query_string)
return web_view_query_string
end
end
end
rescue WaitError
raise WaitError.new('Could not find any scrollable views')
end
end
|
#flash(query_string) ⇒ Object
227
228
229
|
# File 'lib/calabash-android/operations.rb', line 227
def flash(query_string)
map(query_string, :flash)
end
|
#get_activity_orientation ⇒ Object
Note: Android 2.2 will always return either portrait or landscape, not reverse_portrait or reverse_landscape
205
206
207
|
# File 'lib/calabash-android/operations.rb', line 205
def get_activity_orientation
perform_action("get_activity_orientation")
end
|
#get_preferences(name) ⇒ Object
179
180
181
|
# File 'lib/calabash-android/operations.rb', line 179
def get_preferences(name)
default_device.get_preferences(name)
end
|
#hide_soft_keyboard ⇒ Object
918
919
920
|
# File 'lib/calabash-android/operations.rb', line 918
def hide_soft_keyboard
perform_action('hide_soft_keyboard')
end
|
#html(q) ⇒ Object
963
964
965
|
# File 'lib/calabash-android/operations.rb', line 963
def html(q)
query(q).map {|e| e['html']}
end
|
#http(path, data = {}, options = {}) ⇒ Object
941
942
943
|
# File 'lib/calabash-android/operations.rb', line 941
def http(path, data = {}, options = {})
default_device.http(path, data, options)
end
|
#http_put(path, data = {}, options = {}) ⇒ Object
945
946
947
|
# File 'lib/calabash-android/operations.rb', line 945
def http_put(path, data = {}, options = {})
default_device.http_put(path, data, options)
end
|
#install_app(app_path) ⇒ Object
113
114
115
|
# File 'lib/calabash-android/operations.rb', line 113
def install_app(app_path)
default_device.install_app(app_path)
end
|
#interpolate(recording, options = {}) ⇒ Object
1263
1264
1265
|
# File 'lib/calabash-android/operations.rb', line 1263
def interpolate(recording, options={})
ni
end
|
#label(uiquery) ⇒ Object
905
906
907
|
# File 'lib/calabash-android/operations.rb', line 905
def label(uiquery)
ni
end
|
#load_dylib(file_path, classes = []) ⇒ Object
958
959
960
961
|
# File 'lib/calabash-android/operations.rb', line 958
def load_dylib(file_path, classes = [])
uploaded_file = upload_file(file_path)
http('/load-dylib', {path: uploaded_file, classes: classes})
end
|
#load_playback_data(recording, options = {}) ⇒ Object
1255
1256
1257
|
# File 'lib/calabash-android/operations.rb', line 1255
def load_playback_data(recording,options={})
ni
end
|
#log(message) ⇒ Object
56
57
58
|
# File 'lib/calabash-android/operations.rb', line 56
def log(message)
$stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
end
|
#macro(txt) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/calabash-android/operations.rb', line 60
def macro(txt)
if self.respond_to?(:step)
step(txt)
else
Then(txt)
end
end
|
#make_http_request(options) ⇒ Object
1318
1319
1320
|
# File 'lib/calabash-android/operations.rb', line 1318
def make_http_request(options)
default_device.make_http_request(options)
end
|
#map(query, method_name, *method_args) ⇒ Object
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
|
# File 'lib/calabash-android/operations.rb', line 1299
def map(query, method_name, *method_args)
operation_map = {
:method_name => method_name,
:arguments => method_args
}
res = http("/map",
{:query => query, :operation => operation_map})
res = JSON.parse(res)
if res['outcome'] != 'SUCCESS'
screenshot_and_raise "map #{query}, #{method_name} failed because: #{res['reason']}\n#{res['details']}"
end
res['results']
end
|
#ni ⇒ Object
276
277
278
|
# File 'lib/calabash-android/operations.rb', line 276
def ni
raise "Not yet implemented."
end
|
#page(clz, *args) ⇒ Object
simple page object helper
284
285
286
|
# File 'lib/calabash-android/operations.rb', line 284
def page(clz, *args)
clz.new(self, *args)
end
|
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/calabash-android/operations.rb', line 82
def perform_action(action, *arguments)
if removed_actions.include?(action)
puts "\e[31mError: The action '#{action}' was removed in calabash-android 0.5\e[0m"
puts 'Solutions that do not require the removed action can be found on:'
puts "\e[36mhttps://github.com/calabash/calabash-android/blob/master/migrating_to_calabash_0.5.md\##{action}\e[0m"
elsif deprecated_actions.has_key?(action)
puts "\e[31mWarning: The action '#{action}' is deprecated\e[0m"
puts "\e[32mUse '#{deprecated_actions[action]}' instead\e[0m"
end
default_device.perform_action(action, *arguments)
end
|
76
77
78
79
80
|
# File 'lib/calabash-android/operations.rb', line 76
def performAction(action, *arguments)
puts "Warning: The method performAction is deprecated. Please use perform_action instead."
perform_action(action, *arguments)
end
|
#playback(recording, options = {}) ⇒ Object
1259
1260
1261
|
# File 'lib/calabash-android/operations.rb', line 1259
def playback(recording, options={})
ni
end
|
986
987
988
|
# File 'lib/calabash-android/operations.rb', line 986
def press_back_button
press_button('KEYCODE_BACK')
end
|
982
983
984
|
# File 'lib/calabash-android/operations.rb', line 982
def press_button(key)
perform_action('press_key', key)
end
|
994
995
996
|
# File 'lib/calabash-android/operations.rb', line 994
def press_down_button
press_button('KEYCODE_DPAD_DOWN')
end
|
1010
1011
1012
|
# File 'lib/calabash-android/operations.rb', line 1010
def press_enter_button
press_button('KEYCODE_ENTER')
end
|
1002
1003
1004
|
# File 'lib/calabash-android/operations.rb', line 1002
def press_left_button
press_button('KEYCODE_DPAD_LEFT')
end
|
990
991
992
|
# File 'lib/calabash-android/operations.rb', line 990
def
press_button('KEYCODE_MENU')
end
|
1006
1007
1008
|
# File 'lib/calabash-android/operations.rb', line 1006
def press_right_button
press_button('KEYCODE_DPAD_RIGHT')
end
|
998
999
1000
|
# File 'lib/calabash-android/operations.rb', line 998
def press_up_button
press_button('KEYCODE_DPAD_UP')
end
|
972
973
974
975
976
977
978
979
980
|
# File 'lib/calabash-android/operations.rb', line 972
def press_user_action_button(action_name=nil)
wait_for_keyboard
if action_name.nil?
perform_action("press_user_action_button")
else
perform_action("press_user_action_button", action_name)
end
end
|
#pull(remote, local) ⇒ Object
134
135
136
|
# File 'lib/calabash-android/operations.rb', line 134
def pull(remote, local)
default_device.pull(remote, local)
end
|
#push(local, remote) ⇒ Object
138
139
140
|
# File 'lib/calabash-android/operations.rb', line 138
def push(local, remote)
default_device.push(local, remote)
end
|
#query(uiquery, *args) ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/calabash-android/operations.rb', line 209
def query(uiquery, *args)
converted_args = []
args.each do |arg|
if arg.is_a?(Hash) and arg.count == 1
if arg.values.is_a?(Array) && arg.values.count == 1
values = arg.values.flatten
else
values = [arg.values]
end
converted_args << {:method_name => arg.keys.first, :arguments => values}
else
converted_args << arg
end
end
map(uiquery,:query,*converted_args)
end
|
#record_begin ⇒ Object
1267
1268
1269
|
# File 'lib/calabash-android/operations.rb', line 1267
def record_begin
ni
end
|
#record_end(file_name) ⇒ Object
1271
1272
1273
|
# File 'lib/calabash-android/operations.rb', line 1271
def record_end(file_name)
ni
end
|
#reinstall_apps ⇒ Object
105
106
107
|
# File 'lib/calabash-android/operations.rb', line 105
def reinstall_apps
default_device.reinstall_apps
end
|
#reinstall_test_server ⇒ Object
109
110
111
|
# File 'lib/calabash-android/operations.rb', line 109
def reinstall_test_server
default_device.reinstall_test_server
end
|
#removed_actions ⇒ Object
95
96
97
|
# File 'lib/calabash-android/operations.rb', line 95
def removed_actions
@removed_actions ||= File.readlines(File.join(File.dirname(__FILE__), 'removed_actions.txt')).map(&:chomp)
end
|
#rotate(dir) ⇒ Object
1213
1214
1215
|
# File 'lib/calabash-android/operations.rb', line 1213
def rotate(dir)
ni
end
|
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object
155
156
157
|
# File 'lib/calabash-android/operations.rb', line 155
def screenshot(options={:prefix => nil, :name => nil})
default_device.screenshot(options)
end
|
#screenshot_and_raise(e, options = nil) ⇒ Object
909
910
911
912
913
914
915
916
|
# File 'lib/calabash-android/operations.rb', line 909
def screenshot_and_raise(e, options = nil)
if options
screenshot_embed options
else
screenshot_embed
end
raise e
end
|
#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
150
151
152
153
|
# File 'lib/calabash-android/operations.rb', line 150
def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
path = default_device.screenshot(options)
embed(path, "image/png", options[:label] || File.basename(path))
end
|
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
|
# File 'lib/calabash-android/operations.rb', line 1114
def scroll(query_string, direction)
if direction != :up && direction != :down
raise 'Only upwards and downwards scrolling is supported for now'
end
action = lambda do
elements = query(query_string)
raise "No elements found. Query: #{query_string}" if elements.empty?
if elements.length > 1
query_string = "#{query_string} index:0"
end
element = elements.first
response = query(query_string, :getFirstVisiblePosition).first
if response.is_a?(Hash) && response.has_key?("error") scroll_x = 0
scroll_y = 0
width = element['rect']['width']
height = element['rect']['height']
if direction == :up
scroll_y = -height/2
else
scroll_y = height/2
end
query(query_string, {scrollBy: [scroll_x.to_i, scroll_y.to_i]})
else first_position = response.to_i
last_position = query(query_string, :getLastVisiblePosition).first.to_i
selection_index = if direction == :up
[first_position + [first_position - last_position + 1, -1].min, 0].max
elsif direction == :down
first_position + [last_position - first_position, 1].max
end
query(query_string, setSelection: selection_index)
end
end
when_element_exists(query_string, action: action)
end
|
1110
1111
1112
|
# File 'lib/calabash-android/operations.rb', line 1110
def scroll_down(options={})
scroll(find_scrollable_view(options), :down)
end
|
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
|
# File 'lib/calabash-android/operations.rb', line 1161
def scroll_to(query_string, options={})
options[:action] ||= lambda {}
all_query_string = query_string
unless all_query_string.chomp.downcase.start_with?('all')
all_query_string = "all #{all_query_string}"
end
wait_for_element_exists(all_query_string)
element = query(all_query_string).first
raise "No elements found. Query: #{all_query_string}" if element.nil?
element_y = element['rect']['y']
element_height = element['rect']['height']
element_bottom = element_y + element_height
scroll_view_query_string = options[:container] || if element.has_key?('html')
"android.webkit.WebView id:'#{element['webView']}'"
else
"#{all_query_string} parent android.widget.ScrollView index:0"
end
scroll_element = query(scroll_view_query_string).first
raise "Could not find parent scroll view. Query: '#{escape_quotes(scroll_view_query_string)}'" if scroll_element.nil?
scroll_element_y = scroll_element['rect']['y']
scroll_element_height = scroll_element['rect']['height']
if element_bottom > scroll_element_y + scroll_element_height
scroll_by_y = element_bottom - (scroll_element_y + scroll_element_height)
elsif element_y < scroll_element_y
scroll_by_y = element_y - scroll_element_y
else
scroll_by_y = 0
end
if scroll_by_y != 0
result = query(scroll_view_query_string, {scrollBy: [0, scroll_by_y]}).first
raise 'Could not scroll parent view' if result != '<VOID>'
end
visibility_query_string = all_query_string[4..-1]
when_element_exists(visibility_query_string, options)
end
|
1208
1209
1210
1211
|
# File 'lib/calabash-android/operations.rb', line 1208
def scroll_to_row(uiquery,number)
query(uiquery, {:smoothScrollToPosition => number})
puts "TODO:detect end of scroll - use sleep for now"
end
|
1106
1107
1108
|
# File 'lib/calabash-android/operations.rb', line 1106
def scroll_up(options={})
scroll(find_scrollable_view(options), :up)
end
|
1019
1020
1021
1022
1023
1024
1025
1026
1027
|
# File 'lib/calabash-android/operations.rb', line 1019
def (view_uiquery, )
long_press(view_uiquery)
container_class = 'com.android.internal.view.menu.ListMenuItemView'
wait_for_element_exists(container_class)
combined_query_string = "#{container_class} descendant #{}"
touch(combined_query_string)
end
|
#select_item_from_spinner(item_query_string, options = {}) ⇒ Object
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
|
# File 'lib/calabash-android/operations.rb', line 1029
def select_item_from_spinner(item_query_string, options={})
spinner_query_string = options[:spinner] || "android.widget.AbsSpinner"
direction = options[:direction] || :down
count = query(spinner_query_string, :getCount).first
scroll_view_query_string = options[:scroll_view] || "android.widget.AbsListView index:0"
unless direction == :up || direction == :down
raise "Invalid direction '#{direction}'. Only upwards and downwards scrolling is supported"
end
touch(spinner_query_string)
change_direction = false
wait_for({retry_frequency: 0}.merge(options)) do
if query(item_query_string).empty?
scroll(scroll_view_query_string, direction)
if change_direction
direction = direction == :up ? :down : :up
change_direction = false
else
if direction == :down
change_direction = true if query(scroll_view_query_string, :getLastVisiblePosition).first+1 == count
elsif direction == :up
change_direction = true if query(scroll_view_query_string, :getFirstVisiblePosition).first == 0
end
end
false
else
true
end
end
touch(item_query_string)
end
|
1014
1015
1016
1017
|
# File 'lib/calabash-android/operations.rb', line 1014
def (identifier, options={})
tap_when_element_exists("DropDownListView * marked:'#{identifier}'", options)
end
|
#server_version ⇒ Object
163
164
165
|
# File 'lib/calabash-android/operations.rb', line 163
def server_version
default_device.server_version
end
|
#set_activity_orientation(orientation) ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/calabash-android/operations.rb', line 191
def set_activity_orientation(orientation)
unless orientation.is_a?(Symbol)
raise ArgumentError, "Orientation is not a symbol"
end
unless orientation == :landscape || orientation == :portrait ||
orientation == :reverse_landscape || orientation == :reverse_portrait
raise ArgumentError, "Invalid orientation given. Use :landscape, :portrait, :reverse_landscape, or :reverse_portrait"
end
perform_action("set_activity_orientation", orientation.to_s)
end
|
#set_date(query_string, year_or_datestring, month = nil, day = nil) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/calabash-android/operations.rb', line 247
def set_date(query_string, year_or_datestring, month=nil, day=nil)
wait_for_element_exists(query_string)
if month.nil? && day.nil? && year_or_datestring.is_a?(String)
date = Date.parse(year_or_datestring)
set_date(query_string, date.year, date.month, date.day)
else
year = year_or_datestring
query(query_string, updateDate: [year, month-1, day])
end
end
|
#set_default_device(device) ⇒ Object
72
73
74
|
# File 'lib/calabash-android/operations.rb', line 72
def set_default_device(device)
@@default_device = device
end
|
#set_gps_coordinates(latitude, longitude) ⇒ Object
175
176
177
|
# File 'lib/calabash-android/operations.rb', line 175
def set_gps_coordinates(latitude, longitude)
default_device.set_gps_coordinates(latitude, longitude)
end
|
#set_gps_coordinates_from_location(location) ⇒ Object
171
172
173
|
# File 'lib/calabash-android/operations.rb', line 171
def set_gps_coordinates_from_location(location)
default_device.set_gps_coordinates_from_location(location)
end
|
#set_preferences(name, hash) ⇒ Object
183
184
185
|
# File 'lib/calabash-android/operations.rb', line 183
def set_preferences(name, hash)
default_device.set_preferences(name, hash)
end
|
#set_text(uiquery, txt) ⇒ Object
967
968
969
970
|
# File 'lib/calabash-android/operations.rb', line 967
def set_text(uiquery, txt)
puts "set_text is deprecated. Use enter_text instead"
enter_text(uiquery, txt)
end
|
#set_time(query_string, hour_or_timestring, minute = nil) ⇒ Object
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/calabash-android/operations.rb', line 259
def set_time(query_string, hour_or_timestring, minute=nil)
wait_for_element_exists(query_string)
if minute.nil? && hour_or_timestring.is_a?(String)
time = Time.parse(hour_or_timestring)
set_time(query_string, time.hour, time.min)
else
hour = hour_or_timestring
query(query_string, setCurrentHour: hour)
query(query_string, setCurrentMinute: minute)
end
end
|
#shutdown_test_server ⇒ Object
146
147
148
|
# File 'lib/calabash-android/operations.rb', line 146
def shutdown_test_server
default_device.shutdown_test_server
end
|
#start_test_server_in_background(options = {}, &block) ⇒ Object
142
143
144
|
# File 'lib/calabash-android/operations.rb', line 142
def start_test_server_in_background(options={}, &block)
default_device.start_test_server_in_background(options, &block)
end
|
#step_deprecated ⇒ Object
937
938
939
|
# File 'lib/calabash-android/operations.rb', line 937
def step_deprecated
puts 'Warning: This predefined step is deprecated.'
end
|
#swipe(query_string, options = {}) ⇒ Object
1070
1071
1072
|
# File 'lib/calabash-android/operations.rb', line 1070
def swipe(query_string, options={})
raise 'Swipe not implemented. Use flick or pan instead.'
end
|
#uninstall_apps ⇒ Object
121
122
123
124
|
# File 'lib/calabash-android/operations.rb', line 121
def uninstall_apps
default_device.uninstall_app(package_name(default_device.test_server_path))
default_device.uninstall_app(package_name(default_device.app_path))
end
|
#update_app(app_path) ⇒ Object
117
118
119
|
# File 'lib/calabash-android/operations.rb', line 117
def update_app(app_path)
default_device.update_app(app_path)
end
|
#upload_file(file_path) ⇒ String
Returns The path of the uploaded file on the device.
950
951
952
953
954
|
# File 'lib/calabash-android/operations.rb', line 950
def upload_file(file_path)
name = File.basename(file_path)
device_tmp_path = http_put('/add-file', File.binread(file_path))
http('/move-cache-file-to-public', {from: device_tmp_path, name: name})
end
|
#url_for(method) ⇒ Object
1314
1315
1316
|
# File 'lib/calabash-android/operations.rb', line 1314
def url_for( method )
default_device.url_for(method)
end
|
#view_with_mark_exists(expected_mark) ⇒ Object
1229
1230
1231
|
# File 'lib/calabash-android/operations.rb', line 1229
def view_with_mark_exists(expected_mark)
element_exists( "android.view.View marked:'#{expected_mark}'" )
end
|
#wake_up ⇒ Object
126
127
128
|
# File 'lib/calabash-android/operations.rb', line 126
def wake_up
default_device.wake_up()
end
|