lib/calabash-android/operations.rb in calabash-android-0.4.0.pre11 vs lib/calabash-android/operations.rb in calabash-android-0.4.0.pre15
- old
+ new
@@ -4,16 +4,20 @@
require 'rubygems'
require 'json'
require 'socket'
require 'timeout'
require 'calabash-android/helpers'
+require 'calabash-android/wait_helpers'
+require 'calabash-android/version'
require 'retriable'
+require 'cucumber'
module Calabash module Android
module Operations
+ include Calabash::Android::WaitHelpers
def log(message)
$stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
end
@@ -84,23 +88,23 @@
def set_gps_coordinates(latitude, longitude)
default_device.set_gps_coordinates(latitude, longitude)
end
- def wait_for(timeout, &block)
- value = nil
- begin
- Timeout::timeout(timeout) do
- until (value = block.call)
- sleep 0.3
- end
- end
- rescue Exception => e
- raise e
- end
- value
- end
+ #def wait_for(timeout, &block)
+ # value = nil
+ # begin
+ # Timeout::timeout(timeout) do
+ # until (value = block.call)
+ # sleep 0.3
+ # end
+ # end
+ # rescue Exception => e
+ # raise e
+ # end
+ # value
+ #end
def query(uiquery, *args)
converted_args = []
args.each do |arg|
if arg.is_a?(Hash) and arg.count == 1
@@ -175,11 +179,11 @@
log result
pn = package_name(app_path)
succeeded = `#{adb_command} shell pm list packages`.include?("package:#{pn}")
unless succeeded
- Cucumber.wants_to_quit = true
+ ::Cucumber.wants_to_quit = true
raise "#{pn} did not get installed. Aborting!"
end
end
def uninstall_app(package_name)
@@ -323,11 +327,11 @@
cmd = "#{adb_command} shell am instrument sh.calaba.android.test/sh.calaba.instrumentationbackend.ClearAppData"
raise "Could not clear data" unless system(cmd)
end
def start_test_server_in_background(options={})
- raise "Will not start test server because of previous failures." if Cucumber.wants_to_quit
+ raise "Will not start test server because of previous failures." if ::Cucumber.wants_to_quit
if keyguard_enabled?
wake_up
end
@@ -367,16 +371,43 @@
raise "Not ready"
else
log "Instrumentation backend is ready!"
end
end
+ rescue Exception => e
- rescue
msg = "Unable to make connection to Calabash Test Server at http://127.0.0.1:#{@server_port}/\n"
msg << "Please check the logcat output for more info about what happened\n"
raise msg
end
+
+ log "Checking client-server version match..."
+ response = perform_action('version')
+ unless response['success']
+ msg = ["Unable to obtain Test Server version. "]
+ msg << "Please delete your test_servers"
+ msg << "and re-run calabash-android run..."
+ msg_s = msg.join("\n")
+ log(msg_s)
+ raise msg_s
+ end
+ unless response['message'] == Calabash::Android::SERVER_VERSION
+
+ msg = ["Calabash Client and Test-server version mismatch."]
+ msg << "Client version #{Calabash::Android::VERSION}"
+ msg << "Test-server version #{response['message']}"
+ msg << "Expected Test-server version #{Calabash::Android::SERVER_VERSION}"
+ msg << "\n\nSolution:\n\n"
+ msg << "Please delete your test_servers"
+ msg << "and re-run calabash-android run..."
+ msg_s = msg.join("\n")
+ log(msg_s)
+ raise msg_s
+ end
+ log("Client and server versions match. Proceeding...")
+
+
end
def shutdown_test_server
begin
http("/kill")
@@ -406,10 +437,9 @@
ni
end
def screenshot_and_raise(msg)
screenshot_embed
- sleep 5
raise(msg)
end
def touch(uiquery,*args)
raise "Cannot touch nil" unless uiquery