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
-
#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
-
#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
-
#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, *args) ⇒ 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
779
780
781
|
# File 'lib/calabash-android/operations.rb', line 779
def app_to_background(secs)
ni
end
|
#backdoor(sel, arg) ⇒ Object
837
838
839
|
# File 'lib/calabash-android/operations.rb', line 837
def backdoor(sel, arg)
ni
end
|
#cell_swipe(options = {}) ⇒ Object
754
755
756
|
# File 'lib/calabash-android/operations.rb', line 754
def cell_swipe(options={})
ni
end
|
#check_element_does_not_exist(query) ⇒ Object
801
802
803
804
805
|
# File 'lib/calabash-android/operations.rb', line 801
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
795
796
797
798
799
|
# File 'lib/calabash-android/operations.rb', line 795
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
807
808
809
|
# File 'lib/calabash-android/operations.rb', line 807
def check_view_with_mark_exists(expected_mark)
check_element_exists( "view marked:'#{expected_mark}'" )
end
|
#clear_app_data ⇒ Object
79
80
81
|
# File 'lib/calabash-android/operations.rb', line 79
def clear_app_data
default_device.clear_app_data
end
|
#clear_preferences(name) ⇒ Object
128
129
130
|
# File 'lib/calabash-android/operations.rb', line 128
def clear_preferences(name)
default_device.clear_preferences(name)
end
|
#connect_to_test_server ⇒ Object
175
176
177
178
179
|
# File 'lib/calabash-android/operations.rb', line 175
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
23
24
25
|
# File 'lib/calabash-android/operations.rb', line 23
def current_activity
`#{default_device.adb_command} shell dumpsys window windows`.each_line.grep(/mFocusedApp.+[\.\/]([^.\/\}]+)\}/){$1}.first
end
|
#default_device ⇒ Object
39
40
41
42
43
44
|
# File 'lib/calabash-android/operations.rb', line 39
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
181
182
183
184
185
|
# File 'lib/calabash-android/operations.rb', line 181
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
758
759
760
|
# File 'lib/calabash-android/operations.rb', line 758
def done
ni
end
|
#each_item(opts = {:query => "android.widget.ListView", :post_scroll => 0.2}, &block) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/calabash-android/operations.rb', line 144
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
783
784
785
|
# File 'lib/calabash-android/operations.rb', line 783
def element_does_not_exist(uiquery)
query(uiquery).empty?
end
|
#element_exists(uiquery) ⇒ Object
787
788
789
|
# File 'lib/calabash-android/operations.rb', line 787
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
812
813
814
|
# File 'lib/calabash-android/operations.rb', line 812
def element_is_not_hidden(uiquery)
ni
end
|
#fail(msg = "Error. Check log for details.", options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
108
109
110
|
# File 'lib/calabash-android/operations.rb', line 108
def fail(msg="Error. Check log for details.", options={:prefix => nil, :name => nil, :label => nil})
screenshot_and_raise(msg, options)
end
|
#get_preferences(name) ⇒ Object
120
121
122
|
# File 'lib/calabash-android/operations.rb', line 120
def get_preferences(name)
default_device.get_preferences(name)
end
|
#html(q) ⇒ Object
733
734
735
|
# File 'lib/calabash-android/operations.rb', line 733
def html(q)
query(q).map {|e| e['html']}
end
|
#http(path, data = {}, options = {}) ⇒ Object
729
730
731
|
# File 'lib/calabash-android/operations.rb', line 729
def http(path, data = {}, options = {})
default_device.http(path, data, options)
end
|
#install_app(app_path) ⇒ Object
62
63
64
|
# File 'lib/calabash-android/operations.rb', line 62
def install_app(app_path)
default_device.install_app(app_path)
end
|
#interpolate(recording, options = {}) ⇒ Object
825
826
827
|
# File 'lib/calabash-android/operations.rb', line 825
def interpolate(recording, options={})
ni
end
|
#label(uiquery) ⇒ Object
698
699
700
|
# File 'lib/calabash-android/operations.rb', line 698
def label(uiquery)
ni
end
|
#load_playback_data(recording, options = {}) ⇒ Object
817
818
819
|
# File 'lib/calabash-android/operations.rb', line 817
def load_playback_data(recording,options={})
ni
end
|
#log(message) ⇒ Object
27
28
29
|
# File 'lib/calabash-android/operations.rb', line 27
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
31
32
33
34
35
36
37
|
# File 'lib/calabash-android/operations.rb', line 31
def macro(txt)
if self.respond_to?(:step)
step(txt)
else
Then(txt)
end
end
|
#make_http_request(options) ⇒ Object
860
861
862
|
# File 'lib/calabash-android/operations.rb', line 860
def make_http_request(options)
default_device.make_http_request(options)
end
|
#map(query, method_name, *method_args) ⇒ Object
841
842
843
844
845
846
847
848
849
850
851
852
853
854
|
# File 'lib/calabash-android/operations.rb', line 841
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
160
161
162
|
# File 'lib/calabash-android/operations.rb', line 160
def ni
raise "Not yet implemented."
end
|
#page(clz, *args) ⇒ Object
simple page object helper
168
169
170
|
# File 'lib/calabash-android/operations.rb', line 168
def page(clz, *args)
clz.new(self, *args)
end
|
50
51
52
|
# File 'lib/calabash-android/operations.rb', line 50
def performAction(action, *arguments)
default_device.perform_action(action, *arguments)
end
|
#pinch(in_out, options = {}) ⇒ Object
771
772
773
|
# File 'lib/calabash-android/operations.rb', line 771
def pinch(in_out,options={})
ni
end
|
#playback(recording, options = {}) ⇒ Object
821
822
823
|
# File 'lib/calabash-android/operations.rb', line 821
def playback(recording, options={})
ni
end
|
#pull(remote, local) ⇒ Object
83
84
85
|
# File 'lib/calabash-android/operations.rb', line 83
def pull(remote, local)
default_device.pull(remote, local)
end
|
#push(local, remote) ⇒ Object
87
88
89
|
# File 'lib/calabash-android/operations.rb', line 87
def push(local, remote)
default_device.push(local, remote)
end
|
#query(uiquery, *args) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/calabash-android/operations.rb', line 132
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
829
830
831
|
# File 'lib/calabash-android/operations.rb', line 829
def record_begin
ni
end
|
#record_end(file_name) ⇒ Object
833
834
835
|
# File 'lib/calabash-android/operations.rb', line 833
def record_end(file_name)
ni
end
|
#reinstall_apps ⇒ Object
54
55
56
|
# File 'lib/calabash-android/operations.rb', line 54
def reinstall_apps
default_device.reinstall_apps
end
|
#reinstall_test_server ⇒ Object
58
59
60
|
# File 'lib/calabash-android/operations.rb', line 58
def reinstall_test_server
default_device.reinstall_test_server
end
|
#rotate(dir) ⇒ Object
775
776
777
|
# File 'lib/calabash-android/operations.rb', line 775
def rotate(dir)
ni
end
|
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object
104
105
106
|
# File 'lib/calabash-android/operations.rb', line 104
def screenshot(options={:prefix => nil, :name => nil})
default_device.screenshot(options)
end
|
#screenshot_and_raise(msg, options = nil) ⇒ Object
702
703
704
705
706
707
708
709
|
# File 'lib/calabash-android/operations.rb', line 702
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
99
100
101
102
|
# File 'lib/calabash-android/operations.rb', line 99
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
|
762
763
764
|
# File 'lib/calabash-android/operations.rb', line 762
def scroll(uiquery,direction)
ni
end
|
766
767
768
769
|
# File 'lib/calabash-android/operations.rb', line 766
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
46
47
48
|
# File 'lib/calabash-android/operations.rb', line 46
def set_default_device(device)
@default_device = device
end
|
#set_gps_coordinates(latitude, longitude) ⇒ Object
116
117
118
|
# File 'lib/calabash-android/operations.rb', line 116
def set_gps_coordinates(latitude, longitude)
default_device.set_gps_coordinates(latitude, longitude)
end
|
#set_gps_coordinates_from_location(location) ⇒ Object
112
113
114
|
# File 'lib/calabash-android/operations.rb', line 112
def set_gps_coordinates_from_location(location)
default_device.set_gps_coordinates_from_location(location)
end
|
#set_preferences(name, hash) ⇒ Object
124
125
126
|
# File 'lib/calabash-android/operations.rb', line 124
def set_preferences(name, hash)
default_device.set_preferences(name, hash)
end
|
#set_text(uiquery, txt) ⇒ Object
737
738
739
740
741
742
743
744
745
746
747
|
# File 'lib/calabash-android/operations.rb', line 737
def set_text(uiquery, txt)
raise "Currently queries are only supported for webviews" unless uiquery.start_with? "webView"
uiquery.slice!(0, "webView".length)
if uiquery =~ /(css|xpath):\s*(.*)/
r = performAction("set_text", $1, $2, txt)
JSON.parse(r["message"])
else
raise "Invalid query #{uiquery}"
end
end
|
#shutdown_test_server ⇒ Object
95
96
97
|
# File 'lib/calabash-android/operations.rb', line 95
def shutdown_test_server
default_device.shutdown_test_server
end
|
#start_test_server_in_background(options = {}) ⇒ Object
91
92
93
|
# File 'lib/calabash-android/operations.rb', line 91
def start_test_server_in_background(options={})
default_device.start_test_server_in_background(options)
end
|
#swipe(dir, options = {}) ⇒ Object
750
751
752
|
# File 'lib/calabash-android/operations.rb', line 750
def swipe(dir,options={})
ni
end
|
#touch(uiquery, *args) ⇒ Object
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
# File 'lib/calabash-android/operations.rb', line 711
def touch(uiquery,*args)
raise "Cannot touch nil" unless uiquery
if uiquery.instance_of? String
elements = query(uiquery, *args)
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"]
performAction("touch_coordinate", center_x, center_y)
end
|
#uninstall_apps ⇒ Object
70
71
72
73
|
# File 'lib/calabash-android/operations.rb', line 70
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
66
67
68
|
# File 'lib/calabash-android/operations.rb', line 66
def update_app(app_path)
default_device.update_app(app_path)
end
|
#url_for(method) ⇒ Object
856
857
858
|
# File 'lib/calabash-android/operations.rb', line 856
def url_for( method )
default_device.url_for(method)
end
|
#view_with_mark_exists(expected_mark) ⇒ Object
791
792
793
|
# File 'lib/calabash-android/operations.rb', line 791
def view_with_mark_exists(expected_mark)
element_exists( "android.view.View marked:'#{expected_mark}'" )
end
|
#wake_up ⇒ Object
75
76
77
|
# File 'lib/calabash-android/operations.rb', line 75
def wake_up
default_device.wake_up()
end
|