lib/calabash-android/operations.rb in calabash-android-0.4.20.1 vs lib/calabash-android/operations.rb in calabash-android-0.4.21

- old
+ new

@@ -20,11 +20,11 @@ module Operations include Calabash::Android::WaitHelpers include Calabash::Android::TouchHelpers def current_activity - `#{default_device.adb_command} shell dumpsys window windows`.each_line.grep(/mFocusedApp.+[\.\/]([^.\/\}]+)\}/){$1}.first + `#{default_device.adb_command} shell dumpsys window windows`.each_line.grep(/mFocusedApp.+[\.\/]([^.\s\/\}]+)/){$1}.first end def log(message) $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose") end @@ -319,32 +319,33 @@ end def make_http_request(options) - body = nil begin unless @http @http = init_request(options) end header = options[:header] || {} header["Content-Type"] = "application/json;charset=utf-8" options[:header] = header - if options[:method] == :post - body = @http.post(options[:uri], options).body + + response = if options[:method] == :post + @http.post(options[:uri], options) else - body = @http.get(options[:uri], options).body + @http.get(options[:uri], options) end + raise Errno::ECONNREFUSED if response.status_code == 502 + response.body rescue Exception => e if @http @http.reset_all @http=nil end raise e end - body end def init_request(options) http = HTTPClient.new configure_http(http, options) @@ -551,10 +552,15 @@ end def shutdown_test_server begin - http("/kill") + begin + http("/kill") + rescue HTTPClient::KeepAliveDisconnected + # Do not react if the server is not responding + end + Timeout::timeout(3) do sleep 0.3 while app_running? end rescue Timeout::Error log ("Could not kill app. Waited to 3 seconds.")