Module: Calabash::Android::Operations
- Defined in:
- lib/calabash-android/operations.rb
Instance Method Summary collapse
-
#adb_command ⇒ Object
adb.
- #backdoor(sel, arg) ⇒ Object
- #background(secs) ⇒ 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
-
#connect_to_test_server ⇒ Object
app life cycle.
- #disconnect_from_test_server ⇒ Object
- #done ⇒ Object
- #element_exists(uiquery) ⇒ Object
-
#element_is_not_hidden(uiquery) ⇒ Object
a better name would be element_exists_and_is_not_hidden.
- #html(q) ⇒ Object
- #http(options, data = nil) ⇒ Object
- #interpolate(recording, options = {}) ⇒ Object
- #is_windows? ⇒ Boolean
- #label(uiquery) ⇒ Object
- #load_playback_data(recording, options = {}) ⇒ Object
- #log(message) ⇒ Object
- #macro(txt) ⇒ Object
- #make_http_request(url, req) ⇒ Object
- #map(query, method_name, *method_args) ⇒ Object
- #ni ⇒ Object
- #performAction(action, *arguments) ⇒ Object
- #pinch(in_out, options = {}) ⇒ Object
- #playback(recording, options = {}) ⇒ Object
- #query(uiquery, *args) ⇒ Object
- #record_begin ⇒ Object
- #record_end(file_name) ⇒ Object
- #rotate(dir) ⇒ Object
- #screenshot ⇒ Object
- #screenshot_and_raise(msg) ⇒ Object
- #scroll(uiquery, direction) ⇒ Object
- #scroll_to_row(uiquery, number) ⇒ Object
- #set_gps_coordinates(latitude, longitude) ⇒ Object
-
#set_gps_coordinates_from_location(location) ⇒ Object
location.
- #set_text(uiquery, txt) ⇒ Object
- #swipe(dir, options = {}) ⇒ Object
- #take_screenshot ⇒ Object
- #touch(uiquery, options = {}) ⇒ Object
- #url_for(verb) ⇒ Object
- #view_with_mark_exists(expected_mark) ⇒ Object
- #wait_for(timeout, &block) ⇒ Object
Instance Method Details
#adb_command ⇒ Object
adb
95 96 97 98 99 100 101 |
# File 'lib/calabash-android/operations.rb', line 95 def adb_command if is_windows? %Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe" #{ENV["ADB_DEVICE_ARG"]}) else %Q(#{ENV["ANDROID_HOME"]}/platform-tools/adb #{ENV["ADB_DEVICE_ARG"]}) end end |
#backdoor(sel, arg) ⇒ Object
255 256 257 |
# File 'lib/calabash-android/operations.rb', line 255 def backdoor(sel, arg) ni end |
#background(secs) ⇒ Object
201 202 203 |
# File 'lib/calabash-android/operations.rb', line 201 def background(secs) ni end |
#cell_swipe(options = {}) ⇒ Object
177 178 179 |
# File 'lib/calabash-android/operations.rb', line 177 def cell_swipe(={}) ni end |
#check_element_does_not_exist(query) ⇒ Object
219 220 221 222 223 |
# File 'lib/calabash-android/operations.rb', line 219 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
213 214 215 216 217 |
# File 'lib/calabash-android/operations.rb', line 213 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
225 226 227 |
# File 'lib/calabash-android/operations.rb', line 225 def check_view_with_mark_exists(expected_mark) check_element_exists( "view marked:'#{expected_mark}'" ) end |
#connect_to_test_server ⇒ Object
app life cycle
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/calabash-android/operations.rb', line 109 def connect_to_test_server log `#{adb_command} forward tcp:#{ENV["TEST_SERVER_PORT"]} tcp:7101` end_time = Time.now + 60 begin Timeout.timeout(10) do @@client = TCPSocket.open('127.0.0.1',ENV["TEST_SERVER_PORT"]) @@client.send("Ping!\n",0) log "Got '#{@@client.readline.strip}' from testserver" end rescue Exception => e log "Got exception:#{e}. Retrying!" sleep(1) retry unless Time.now > end_time end end |
#disconnect_from_test_server ⇒ Object
126 127 128 129 |
# File 'lib/calabash-android/operations.rb', line 126 def disconnect_from_test_server log "Closing connection to test" @@client.close end |
#done ⇒ Object
181 182 183 |
# File 'lib/calabash-android/operations.rb', line 181 def done ni end |
#element_exists(uiquery) ⇒ Object
205 206 207 |
# File 'lib/calabash-android/operations.rb', line 205 def element_exists(uiquery) !query(uiquery).empty? end |
#element_is_not_hidden(uiquery) ⇒ Object
a better name would be element_exists_and_is_not_hidden
230 231 232 |
# File 'lib/calabash-android/operations.rb', line 230 def element_is_not_hidden(uiquery) ni end |
#html(q) ⇒ Object
163 164 165 |
# File 'lib/calabash-android/operations.rb', line 163 def html(q) query(q).map {|e| e['html']} end |
#http(options, data = nil) ⇒ Object
267 268 269 |
# File 'lib/calabash-android/operations.rb', line 267 def http(, data=nil) ni end |
#interpolate(recording, options = {}) ⇒ Object
243 244 245 |
# File 'lib/calabash-android/operations.rb', line 243 def interpolate(recording, ={}) ni end |
#is_windows? ⇒ Boolean
103 104 105 |
# File 'lib/calabash-android/operations.rb', line 103 def is_windows? ENV["OS"] == "Windows_NT" end |
#label(uiquery) ⇒ Object
149 150 151 |
# File 'lib/calabash-android/operations.rb', line 149 def label(uiquery) ni end |
#load_playback_data(recording, options = {}) ⇒ Object
235 236 237 |
# File 'lib/calabash-android/operations.rb', line 235 def load_playback_data(recording,={}) ni end |
#log(message) ⇒ Object
13 14 15 |
# File 'lib/calabash-android/operations.rb', line 13 def log() $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{}" if (ARGV.include? "-v" or ARGV.include? "--verbose") end |
#macro(txt) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/calabash-android/operations.rb', line 30 def macro(txt) if self.respond_to?:step step(txt) else Then(txt) end end |
#make_http_request(url, req) ⇒ Object
276 277 278 |
# File 'lib/calabash-android/operations.rb', line 276 def make_http_request( url, req ) ni end |
#map(query, method_name, *method_args) ⇒ Object
263 264 265 |
# File 'lib/calabash-android/operations.rb', line 263 def map( query, method_name, *method_args ) ni end |
#ni ⇒ Object
89 90 91 |
# File 'lib/calabash-android/operations.rb', line 89 def ni raise "Not yet implemented." end |
#performAction(action, *arguments) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/calabash-android/operations.rb', line 38 def performAction(action, *arguments) log "Action: #{action} - Params: #{arguments.join(', ')}" action = {"command" => action, "arguments" => arguments} Timeout.timeout(300) do begin @@client.send(action.to_json + "\n", 0) #force_encoding('UTF-8') seems to be missing from JRuby result = @@client.readline rescue Exception => e log "Error communicating with test server: #{e}" raise e end log "Result:'" + result.strip + "'" raise "Empty result from TestServer" if result.chomp.empty? result = JSON.parse(result) if not result["success"] then take_screenshot raise result["message"].to_s end return result end rescue Timeout::Error raise Exception, "Step timed out" end |
#pinch(in_out, options = {}) ⇒ Object
193 194 195 |
# File 'lib/calabash-android/operations.rb', line 193 def pinch(in_out,={}) ni end |
#playback(recording, options = {}) ⇒ Object
239 240 241 |
# File 'lib/calabash-android/operations.rb', line 239 def playback(recording, ={}) ni end |
#query(uiquery, *args) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/calabash-android/operations.rb', line 77 def query(uiquery, *args) raise "Currently only queries are only supported for webviews" unless uiquery.start_with? "webView" uiquery.slice!(0, "webView".length) if uiquery =~ /(css|xpath):\s*(.*)/ r = performAction("query", $1, $2) JSON.parse(r["message"]) else raise "Invalid query #{uiquery}" end end |
#record_begin ⇒ Object
247 248 249 |
# File 'lib/calabash-android/operations.rb', line 247 def record_begin ni end |
#record_end(file_name) ⇒ Object
251 252 253 |
# File 'lib/calabash-android/operations.rb', line 251 def record_end(file_name) ni end |
#rotate(dir) ⇒ Object
197 198 199 |
# File 'lib/calabash-android/operations.rb', line 197 def rotate(dir) ni end |
#screenshot ⇒ Object
259 260 261 |
# File 'lib/calabash-android/operations.rb', line 259 def screenshot ni end |
#screenshot_and_raise(msg) ⇒ Object
153 154 155 156 157 |
# File 'lib/calabash-android/operations.rb', line 153 def screenshot_and_raise(msg) take_screenshot sleep 5 raise(msg) end |
#scroll(uiquery, direction) ⇒ Object
185 186 187 |
# File 'lib/calabash-android/operations.rb', line 185 def scroll(uiquery,direction) ni end |
#scroll_to_row(uiquery, number) ⇒ Object
189 190 191 |
# File 'lib/calabash-android/operations.rb', line 189 def scroll_to_row(uiquery,number) ni end |
#set_gps_coordinates(latitude, longitude) ⇒ Object
143 144 145 |
# File 'lib/calabash-android/operations.rb', line 143 def set_gps_coordinates(latitude, longitude) performAction('set_gps_coordinates', latitude, longitude) end |
#set_gps_coordinates_from_location(location) ⇒ Object
location
134 135 136 137 138 139 140 141 |
# File 'lib/calabash-android/operations.rb', line 134 def set_gps_coordinates_from_location(location) require 'geocoder' results = Geocoder.search(location) raise Exception, "Got no results for #{location}" if results.empty? best_result = results.first set_gps_coordinates(best_result.latitude, best_result.longitude) end |
#set_text(uiquery, txt) ⇒ Object
168 169 170 |
# File 'lib/calabash-android/operations.rb', line 168 def set_text(uiquery, txt) ni end |
#swipe(dir, options = {}) ⇒ Object
173 174 175 |
# File 'lib/calabash-android/operations.rb', line 173 def swipe(dir,={}) ni end |
#take_screenshot ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/calabash-android/operations.rb', line 17 def take_screenshot begin Timeout.timeout(30) do file_name = "#{ENV['SCREENSHOT_PATH_PREFIX']}screenshot_#{StepCounter.step_line}.png" log "Taking screenshoot to #{file_name} from device: #{ENV['ADB_DEVICE_ARG']}" system("java -jar #{File.dirname(__FILE__)}/lib/screenShotTaker.jar #{file_name} #{ENV['ADB_DEVICE_ARG']}") log "Screenshot taken" end rescue Timeout::Error raise Exception, "take_screenshot timed out" end end |
#touch(uiquery, options = {}) ⇒ Object
159 160 161 |
# File 'lib/calabash-android/operations.rb', line 159 def touch(uiquery,={}) ni end |
#url_for(verb) ⇒ Object
272 273 274 |
# File 'lib/calabash-android/operations.rb', line 272 def url_for( verb ) ni end |
#view_with_mark_exists(expected_mark) ⇒ Object
209 210 211 |
# File 'lib/calabash-android/operations.rb', line 209 def view_with_mark_exists(expected_mark) element_exists( "view marked:'#{expected_mark}'" ) end |
#wait_for(timeout, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/calabash-android/operations.rb', line 64 def wait_for(timeout, &block) begin Timeout::timeout(timeout) do until block.call sleep 0.3 end end rescue Exception => e take_screenshot raise e end end |