Class: KrakenMobile::Runner::CalabashAndroidRunner
- Inherits:
-
KrakenRunner
- Object
- KrakenRunner
- KrakenMobile::Runner::CalabashAndroidRunner
- Defined in:
- lib/kraken-mobile/runners/calabash/android/android_runner.rb
Constant Summary collapse
- BASE_COMMAND =
"calabash-android run"
Instance Method Summary collapse
- #after_execution(process_number) ⇒ Object
-
#before_all ⇒ Object
——————————- Hooks ——————————-.
- #before_execution(process_number) ⇒ Object
-
#build_execution_command(process_number, general_apk, test_files) ⇒ Object
——————————- Helpers ——————————-.
- #ensure_apks_signed ⇒ Object
-
#initialize(options) ⇒ CalabashAndroidRunner
constructor
A new instance of CalabashAndroidRunner.
-
#run_in_parallel ⇒ Object
——————————- Execution ——————————-.
- #run_tests(test_files, process_number, options) ⇒ Object
Constructor Details
#initialize(options) ⇒ CalabashAndroidRunner
Returns a new instance of CalabashAndroidRunner.
17 18 19 20 21 22 23 24 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 17 def initialize() super() default_runner = KrakenMobile::Constants::CALABASH_ANDROID @devices_manager = DevicesHelper::Manager.new({runner: default_runner, config_path: @options[:config_path]}) @adb_helper = @devices_manager.device_helper @execution_id = Digest::SHA256.hexdigest("#{Time.now.to_f}") @reporter = KrakenMobile::Reporter.new(@execution_id, ) end |
Instance Method Details
#after_execution(process_number) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 53 def after_execution process_number device = @devices_manager.connected_devices[process_number] raise "There is no device for process #{process_number}" unless device @adb_helper.delete_file KrakenMobile::Constants::DEVICE_INBOX_NAME, device.id @adb_helper.delete_file KrakenMobile::Constants::KRAKEN_CONFIGURATION_FILE_NAME, device.id end |
#before_all ⇒ Object
Hooks
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 29 def before_all Dir.mkdir(KrakenMobile::Constants::REPORT_PATH) unless File.exists?(KrakenMobile::Constants::REPORT_PATH) Dir.mkdir("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}") devices_id_list = [] @devices_manager.connected_devices.each_with_index do |device, index| height, width = @adb_helper.screen_size device.id sdk_version = @adb_helper.sdk_version device.id devices_id_list << { user: (index+1), id: device.id, model: device.model, screen_height: height, screen_width: width, sdk: sdk_version } Dir.mkdir("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}") end file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{KrakenMobile::Constants::REPORT_DEVICES_FILE_NAME}.json", 'w') file.puts(devices_id_list.to_json) file.close source_dir = File.("../../../../../../reporter/assets/", __FILE__) FileUtils.cp_r(source_dir, "#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/") end |
#before_execution(process_number) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 46 def before_execution process_number device = @devices_manager.connected_devices[process_number] raise "There is no device for process #{process_number}" unless device @adb_helper.create_file KrakenMobile::Constants::DEVICE_INBOX_NAME, device.id @adb_helper.create_file KrakenMobile::Constants::KRAKEN_CONFIGURATION_FILE_NAME, device.id end |
#build_execution_command(process_number, general_apk, test_files) ⇒ Object
Helpers
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 97 def build_execution_command process_number, general_apk, test_files device = @devices_manager.connected_devices[process_number] raise "Theres not a device for process #{process_number}" unless device apk_path = device.config["apk_path"] ? device.config["apk_path"] : general_apk raise "Invalid apk path" unless apk_path = "--format pretty --format json -o #{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json" execution_command = @command_helper.build_command [BASE_COMMAND, apk_path, , *test_files, "--tags @user#{device.position}"] env_variables = { AUTOTEST: '1', ADB_DEVICE_ARG: device.id, DEVICE_INFO: device.model, TEST_PROCESS_NUMBER: (process_number+1).to_s, SCREENSHOT_PATH: "#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{device.screenshot_prefix}", PROTOCOL: @options[:protocol], RUNNER: KrakenMobile::Constants::CALABASH_ANDROID } env_variables[:CONFIG_PATH] = @options[:config_path] if @options[:config_path] env_variables[:PROPERTIES_PATH] = @options[:properties_path] if @options[:properties_path] exports = @command_helper.build_export_env_command env_variables exports + @command_helper.terminal_command_separator + execution_command end |
#ensure_apks_signed ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 119 def ensure_apks_signed checked_apks = {} @devices_manager.connected_devices.each do |device| apk_path = device.config["apk_path"] ? device.config["apk_path"] : @options[:apk_path] next if checked_apks[apk_path] # Dont check already checked apks raise "APK is not signed, you can resign the app by running kraken-mobile resign #{apk_path}" if !KrakenMobile::CalabashAndroid::ApkSigner.is_apk_signed? apk_path checked_apks[apk_path] = apk_path end end |
#run_in_parallel ⇒ Object
Execution
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 63 def run_in_parallel ensure_apks_signed before_all feature_folder = @options[:feature_folder] devices_connected = @devices_manager.connected_devices groups = FeatureGrouper.file_groups(feature_folder, devices_connected.size) threads = groups.size puts "Running with #{threads} threads: #{groups}" test_results = Parallel.map_with_index( groups, :in_threads => threads, :start => lambda { |group, index| before_execution(index) }, :finish => lambda { |group, index, _| after_execution(index) } ) do |group, index| run_tests(group, index, @options) @reporter.generate_device_report devices_connected[index] end @reporter.generate_general_report end |
#run_tests(test_files, process_number, options) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/kraken-mobile/runners/calabash/android/android_runner.rb', line 87 def run_tests(test_files, process_number, ) command = build_execution_command(process_number, [:apk_path], test_files) puts "\n****** PROCESS #{process_number} STARTED ******\n\n" @command_helper.execute_command(process_number, command) puts "\n****** PROCESS #{process_number} COMPLETED ******\n\n" end |