Module: Calabash::Android::Operations
Defined Under Namespace
Classes: Device
Instance Method Summary
collapse
-
#app_to_background(secs) ⇒ Object
-
#backdoor(sel, arg) ⇒ 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
-
#clear_app_data ⇒ Object
-
#clear_preferences(name) ⇒ Object
-
#connect_to_test_server ⇒ Object
-
#current_activity ⇒ Object
-
#default_device ⇒ Object
-
#disconnect_from_test_server ⇒ Object
-
#done ⇒ Object
-
#double_tap(uiquery, options = {}) ⇒ 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.
-
#fail(msg = "Error. Check log for details.", options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
-
#find_coordinate(uiquery) ⇒ Object
-
#get_preferences(name) ⇒ Object
-
#html(q) ⇒ Object
-
#http(path, data = {}, options = {}) ⇒ Object
-
#install_app(app_path) ⇒ Object
-
#interpolate(recording, options = {}) ⇒ Object
-
#label(uiquery) ⇒ Object
-
#load_playback_data(recording, options = {}) ⇒ Object
-
#log(message) ⇒ Object
-
#long_press(uiquery, options = {}) ⇒ 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.
-
#performAction(action, *arguments) ⇒ Object
-
#pinch(in_out, options = {}) ⇒ Object
-
#playback(recording, options = {}) ⇒ 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
-
#rotate(dir) ⇒ Object
-
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object
-
#screenshot_and_raise(msg, options = nil) ⇒ Object
-
#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
-
#scroll(uiquery, direction) ⇒ Object
-
#scroll_to_row(uiquery, number) ⇒ 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
-
#shutdown_test_server ⇒ Object
-
#start_test_server_in_background(options = {}) ⇒ Object
-
#swipe(dir, options = {}) ⇒ Object
-
#touch(uiquery, options = {}) ⇒ Object
-
#uninstall_apps ⇒ Object
-
#update_app(app_path) ⇒ Object
-
#url_for(method) ⇒ Object
-
#view_with_mark_exists(expected_mark) ⇒ Object
-
#wake_up ⇒ Object
#tap
#handle_error_with_options, #wait_for, #wait_for_elements_do_not_exist, #wait_for_elements_exist, #wait_poll
Instance Method Details
#app_to_background(secs) ⇒ Object
789
790
791
|
# File 'lib/calabash-android/operations.rb', line 789
def app_to_background(secs)
ni
end
|
#backdoor(sel, arg) ⇒ Object
847
848
849
|
# File 'lib/calabash-android/operations.rb', line 847
def backdoor(sel, arg)
ni
end
|
#cell_swipe(options = {}) ⇒ Object
764
765
766
|
# File 'lib/calabash-android/operations.rb', line 764
def cell_swipe(options={})
ni
end
|
#check_element_does_not_exist(query) ⇒ Object
811
812
813
814
815
|
# File 'lib/calabash-android/operations.rb', line 811
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
805
806
807
808
809
|
# File 'lib/calabash-android/operations.rb', line 805
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
817
818
819
|
# File 'lib/calabash-android/operations.rb', line 817
def check_view_with_mark_exists(expected_mark)
check_element_exists( "view marked:'#{expected_mark}'" )
end
|
#clear_app_data ⇒ Object
80
81
82
|
# File 'lib/calabash-android/operations.rb', line 80
def clear_app_data
default_device.clear_app_data
end
|
#clear_preferences(name) ⇒ Object
129
130
131
|
# File 'lib/calabash-android/operations.rb', line 129
def clear_preferences(name)
default_device.clear_preferences(name)
end
|
#connect_to_test_server ⇒ Object
176
177
178
179
180
|
# File 'lib/calabash-android/operations.rb', line 176
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
24
25
26
|
# File 'lib/calabash-android/operations.rb', line 24
def current_activity
`#{default_device.adb_command} shell dumpsys window windows`.each_line.grep(/mFocusedApp.+[\.\/]([^.\/\}]+)\}/){$1}.first
end
|
#default_device ⇒ Object
40
41
42
43
44
45
|
# File 'lib/calabash-android/operations.rb', line 40
def default_device
unless @default_device
@default_device = Device.new(self, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
end
@default_device
end
|
#disconnect_from_test_server ⇒ Object
182
183
184
185
186
|
# File 'lib/calabash-android/operations.rb', line 182
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
768
769
770
|
# File 'lib/calabash-android/operations.rb', line 768
def done
ni
end
|
#double_tap(uiquery, options = {}) ⇒ Object
704
705
706
707
708
|
# File 'lib/calabash-android/operations.rb', line 704
def double_tap(uiquery, options = {})
center_x, center_y = find_coordinate(uiquery)
performAction("double_tap_coordinate", center_x, center_y)
end
|
#each_item(opts = {:query => "android.widget.ListView", :post_scroll => 0.2}, &block) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/calabash-android/operations.rb', line 145
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
793
794
795
|
# File 'lib/calabash-android/operations.rb', line 793
def element_does_not_exist(uiquery)
query(uiquery).empty?
end
|
#element_exists(uiquery) ⇒ Object
797
798
799
|
# File 'lib/calabash-android/operations.rb', line 797
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
822
823
824
|
# File 'lib/calabash-android/operations.rb', line 822
def element_is_not_hidden(uiquery)
ni
end
|
#fail(msg = "Error. Check log for details.", options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
109
110
111
|
# File 'lib/calabash-android/operations.rb', line 109
def fail(msg="Error. Check log for details.", options={:prefix => nil, :name => nil, :label => nil})
screenshot_and_raise(msg, options)
end
|
#find_coordinate(uiquery) ⇒ Object
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
# File 'lib/calabash-android/operations.rb', line 722
def find_coordinate(uiquery)
raise "Cannot find nil" unless uiquery
if uiquery.instance_of? String
elements = query(uiquery)
raise "No elements found. Query: #{uiquery}" if elements.empty?
element = elements.first
else
element = uiquery
element = element.first if element.instance_of?(Array)
end
center_x = element["rect"]["center_x"]
center_y = element["rect"]["center_y"]
[center_x, center_y]
end
|
#get_preferences(name) ⇒ Object
121
122
123
|
# File 'lib/calabash-android/operations.rb', line 121
def get_preferences(name)
default_device.get_preferences(name)
end
|
#html(q) ⇒ Object
744
745
746
|
# File 'lib/calabash-android/operations.rb', line 744
def html(q)
query(q).map {|e| e['html']}
end
|
#http(path, data = {}, options = {}) ⇒ Object
740
741
742
|
# File 'lib/calabash-android/operations.rb', line 740
def http(path, data = {}, options = {})
default_device.http(path, data, options)
end
|
#install_app(app_path) ⇒ Object
63
64
65
|
# File 'lib/calabash-android/operations.rb', line 63
def install_app(app_path)
default_device.install_app(app_path)
end
|
#interpolate(recording, options = {}) ⇒ Object
835
836
837
|
# File 'lib/calabash-android/operations.rb', line 835
def interpolate(recording, options={})
ni
end
|
#label(uiquery) ⇒ Object
691
692
693
|
# File 'lib/calabash-android/operations.rb', line 691
def label(uiquery)
ni
end
|
#load_playback_data(recording, options = {}) ⇒ Object
827
828
829
|
# File 'lib/calabash-android/operations.rb', line 827
def load_playback_data(recording,options={})
ni
end
|
#log(message) ⇒ Object
28
29
30
|
# File 'lib/calabash-android/operations.rb', line 28
def log(message)
$stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
end
|
#long_press(uiquery, options = {}) ⇒ Object
710
711
712
713
714
|
# File 'lib/calabash-android/operations.rb', line 710
def long_press(uiquery, options = {})
center_x, center_y = find_coordinate(uiquery)
performAction("long_press_coordinate", center_x, center_y)
end
|
#macro(txt) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/calabash-android/operations.rb', line 32
def macro(txt)
if self.respond_to?(:step)
step(txt)
else
Then(txt)
end
end
|
#make_http_request(options) ⇒ Object
870
871
872
|
# File 'lib/calabash-android/operations.rb', line 870
def make_http_request(options)
default_device.make_http_request(options)
end
|
#map(query, method_name, *method_args) ⇒ Object
851
852
853
854
855
856
857
858
859
860
861
862
863
864
|
# File 'lib/calabash-android/operations.rb', line 851
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
161
162
163
|
# File 'lib/calabash-android/operations.rb', line 161
def ni
raise "Not yet implemented."
end
|
#page(clz, *args) ⇒ Object
simple page object helper
169
170
171
|
# File 'lib/calabash-android/operations.rb', line 169
def page(clz, *args)
clz.new(self, *args)
end
|
51
52
53
|
# File 'lib/calabash-android/operations.rb', line 51
def performAction(action, *arguments)
default_device.perform_action(action, *arguments)
end
|
#pinch(in_out, options = {}) ⇒ Object
781
782
783
|
# File 'lib/calabash-android/operations.rb', line 781
def pinch(in_out,options={})
ni
end
|
#playback(recording, options = {}) ⇒ Object
831
832
833
|
# File 'lib/calabash-android/operations.rb', line 831
def playback(recording, options={})
ni
end
|
#pull(remote, local) ⇒ Object
84
85
86
|
# File 'lib/calabash-android/operations.rb', line 84
def pull(remote, local)
default_device.pull(remote, local)
end
|
#push(local, remote) ⇒ Object
88
89
90
|
# File 'lib/calabash-android/operations.rb', line 88
def push(local, remote)
default_device.push(local, remote)
end
|
#query(uiquery, *args) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/calabash-android/operations.rb', line 133
def query(uiquery, *args)
converted_args = []
args.each do |arg|
if arg.is_a?(Hash) and arg.count == 1
converted_args << {:method_name => arg.keys.first, :arguments => [ arg.values.first ]}
else
converted_args << arg
end
end
map(uiquery,:query,*converted_args)
end
|
#record_begin ⇒ Object
839
840
841
|
# File 'lib/calabash-android/operations.rb', line 839
def record_begin
ni
end
|
#record_end(file_name) ⇒ Object
843
844
845
|
# File 'lib/calabash-android/operations.rb', line 843
def record_end(file_name)
ni
end
|
#reinstall_apps ⇒ Object
55
56
57
|
# File 'lib/calabash-android/operations.rb', line 55
def reinstall_apps
default_device.reinstall_apps
end
|
#reinstall_test_server ⇒ Object
59
60
61
|
# File 'lib/calabash-android/operations.rb', line 59
def reinstall_test_server
default_device.reinstall_test_server
end
|
#rotate(dir) ⇒ Object
785
786
787
|
# File 'lib/calabash-android/operations.rb', line 785
def rotate(dir)
ni
end
|
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object
105
106
107
|
# File 'lib/calabash-android/operations.rb', line 105
def screenshot(options={:prefix => nil, :name => nil})
default_device.screenshot(options)
end
|
#screenshot_and_raise(msg, options = nil) ⇒ Object
695
696
697
698
699
700
701
702
|
# File 'lib/calabash-android/operations.rb', line 695
def screenshot_and_raise(msg, options = nil)
if options
screenshot_embed options
else
screenshot_embed
end
raise(msg)
end
|
#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
100
101
102
103
|
# File 'lib/calabash-android/operations.rb', line 100
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
|
772
773
774
|
# File 'lib/calabash-android/operations.rb', line 772
def scroll(uiquery,direction)
ni
end
|
776
777
778
779
|
# File 'lib/calabash-android/operations.rb', line 776
def scroll_to_row(uiquery,number)
query(uiquery, {:smoothScrollToPosition => number})
puts "TODO:detect end of scroll - use sleep for now"
end
|
#set_default_device(device) ⇒ Object
47
48
49
|
# File 'lib/calabash-android/operations.rb', line 47
def set_default_device(device)
@default_device = device
end
|
#set_gps_coordinates(latitude, longitude) ⇒ Object
117
118
119
|
# File 'lib/calabash-android/operations.rb', line 117
def set_gps_coordinates(latitude, longitude)
default_device.set_gps_coordinates(latitude, longitude)
end
|
#set_gps_coordinates_from_location(location) ⇒ Object
113
114
115
|
# File 'lib/calabash-android/operations.rb', line 113
def set_gps_coordinates_from_location(location)
default_device.set_gps_coordinates_from_location(location)
end
|
#set_preferences(name, hash) ⇒ Object
125
126
127
|
# File 'lib/calabash-android/operations.rb', line 125
def set_preferences(name, hash)
default_device.set_preferences(name, hash)
end
|
#set_text(uiquery, txt) ⇒ Object
748
749
750
751
752
753
754
755
756
757
|
# File 'lib/calabash-android/operations.rb', line 748
def set_text(uiquery, txt)
view,arguments = uiquery.split(" ",2)
raise "Currently queries are only supported for webviews" unless view.downcase == "webview"
if arguments =~ /(css|xpath):\s*(.*)/
r = performAction("set_text", $1, $2, txt)
else
raise "Invalid query #{arguments}"
end
end
|
#shutdown_test_server ⇒ Object
96
97
98
|
# File 'lib/calabash-android/operations.rb', line 96
def shutdown_test_server
default_device.shutdown_test_server
end
|
#start_test_server_in_background(options = {}) ⇒ Object
92
93
94
|
# File 'lib/calabash-android/operations.rb', line 92
def start_test_server_in_background(options={})
default_device.start_test_server_in_background(options)
end
|
#swipe(dir, options = {}) ⇒ Object
760
761
762
|
# File 'lib/calabash-android/operations.rb', line 760
def swipe(dir,options={})
ni
end
|
#touch(uiquery, options = {}) ⇒ Object
716
717
718
719
720
|
# File 'lib/calabash-android/operations.rb', line 716
def touch(uiquery, options = {})
center_x, center_y = find_coordinate(uiquery)
performAction("touch_coordinate", center_x, center_y)
end
|
#uninstall_apps ⇒ Object
71
72
73
74
|
# File 'lib/calabash-android/operations.rb', line 71
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
67
68
69
|
# File 'lib/calabash-android/operations.rb', line 67
def update_app(app_path)
default_device.update_app(app_path)
end
|
#url_for(method) ⇒ Object
866
867
868
|
# File 'lib/calabash-android/operations.rb', line 866
def url_for( method )
default_device.url_for(method)
end
|
#view_with_mark_exists(expected_mark) ⇒ Object
801
802
803
|
# File 'lib/calabash-android/operations.rb', line 801
def view_with_mark_exists(expected_mark)
element_exists( "android.view.View marked:'#{expected_mark}'" )
end
|
#wake_up ⇒ Object
76
77
78
|
# File 'lib/calabash-android/operations.rb', line 76
def wake_up
default_device.wake_up()
end
|