lib/calabash/android/device.rb in calabash-2.0.0.pre10 vs lib/calabash/android/device.rb in calabash-2.0.0.pre11
- old
+ new
@@ -3,10 +3,14 @@
module Calabash
module Android
# A representation of a Calabash Android device.
# @!visibility private
class Device < ::Calabash::Device
+ require 'calabash/android/device/helper_application'
+
+ include Calabash::Android::Device::HelperApplication
+
attr_reader :adb
def initialize(identifier, server)
super
@adb = ADB.new(identifier)
@@ -473,16 +477,20 @@
def clear_calabash_server_report(application)
if installed_packages.include?(application.test_server.identifier)
parameters =
{
- packageName: application.test_server.identifier,
- className: 'sh.calaba.instrumentationbackend.StatusReporterActivity',
- extras:
- {
+ intent: {
+ flags: 0x10000000,
+ component: {
+ packageName: application.test_server.identifier,
+ className: 'sh.calaba.instrumentationbackend.StatusReporterActivity',
+ },
+ extras: {
method: 'clear'
}
+ }
}
ensure_helper_application_started
start_activity(parameters)
end
@@ -566,11 +574,11 @@
rescue ADB::ADBCallError => e
raise "Failed to start the application: '#{e.stderr.lines.first.chomp}'"
end
begin
- Retriable.retriable(tries: 30, interval: 1, timeout: 30, on: RetryError) do
+ Calabash::Retry.retry(retries: 30, interval: 1, timeout: 30, on_errors: [RetryError]) do
unless test_server_responding?
# Read any message the test-server might have
if calabash_server_failure_exists?(application)
failure_message = read_calabash_sever_failure(application)
@@ -585,11 +593,11 @@
@logger.log('For information, see the adb logcat', :error)
raise 'Could not contact test-server'
end
begin
- Retriable.retriable(tries: 10, interval: 1, timeout: 10) do
+ Calabash::Retry.retry(retries: 10, interval: 1, timeout: 10, on_errors: [RetryError]) do
unless test_server_ready?
raise RetryError
end
end
rescue RetryError => _
@@ -618,11 +626,11 @@
result['result']
end
# @!visibility private
def _stop_app
- Retriable.retriable(tries: 5, interval: 1) do
+ Calabash::Retry.retry(retries: 5, interval: 1) do
begin
http_client.post(HTTP::Request.new('kill'), retries: 1, interval: 0)
rescue HTTP::Error => _
# It's fine that we can't contact the test-server, as it might already have been shut down
if test_server_responding?
@@ -762,12 +770,16 @@
# @!visibility private
def ts_clear_app_data(application)
parameters =
{
- className: 'sh.calaba.instrumentationbackend.ClearAppData2',
- packageName: application.test_server.identifier,
+ intent: {
+ component: {
+ className: 'sh.calaba.instrumentationbackend.ClearAppData2',
+ packageName: application.test_server.identifier
+ }
+ }
}
begin
ensure_instrument_action(application, parameters)
rescue EnsureInstrumentActionError => e
@@ -855,11 +867,11 @@
@logger.log 'Application is already installed. Ensuring right checksum'
installed_app_md5_checksum = md5_checksum_for_app_package(application.identifier)
if application.md5_checksum != installed_app_md5_checksum
- @logger.log("The md5 checksum has changed (#{application.md5_checksum} != #{installed_app_md5_checksum}).", :info)
+ @logger.log("The md5 checksum has changed for '#{application.identifier}' (#{application.md5_checksum} != #{installed_app_md5_checksum}).", :info)
_install_app(application)
end
else
adb_install_app(application)
end
@@ -1153,65 +1165,9 @@
if result['outcome'] != 'SUCCESS'
raise StartActivityError, "Failed to start activity. Reason: #{result['reason']}"
end
true
- end
-
- def ensure_helper_application_started
- unless $_calabash_helper_application_started
- install_helper_application
- start_helper_application
- $_calabash_helper_application_started = true
- end
- end
-
- def helper_application
- Calabash::Android::Application.new(Calabash::Android::HELPER_APPLICATION,
- Calabash::Android::HELPER_APPLICATION_TEST_SERVER)
- end
-
- def helper_application_http_client
- @helper_application_http_client ||= Calabash::HTTP::ForwardingClient.new(http_client, 8451)
- end
-
- # @!visibility private
- def install_helper_application
- begin
- @logger.log "Ensuring helper application is installed"
- ensure_app_installed(helper_application)
- rescue => e
- @logger.log("Unable to install helper application!", :error)
- raise e
- end
-
- $_calabash_helper_application_installed = true
- end
-
- # @!visibility private
- def has_installed_helper_application?
- $_calabash_helper_application_installed
- end
-
- # @!visibility private
- def helper_application_responding?
- begin
- helper_application_http_client.post(HTTP::Request.new('ping'), retries: 1).body == 'pong'
- rescue HTTP::Error => _
- false
- end
- end
-
- def start_helper_application
- extras = "-e test_server_port 8451"
- name = "#{helper_application.test_server.identifier}/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner"
- cmd = "am instrument #{extras} #{name}"
- Logger.debug("Starting global helper application using #{cmd}")
- adb.shell(cmd)
-
- cmd = "am start -e port #{server.test_server_port} -e testServerPort 0 -n #{helper_application.identifier}/.MainActivity"
- Logger.debug("Starting helper application using #{cmd}")
- adb.shell(cmd)
end
# @!visibility private
def params_for_request(parameters)
{json: parameters.to_json}