Class: KrakenMobile::Runner::MonkeyRunner
- Inherits:
-
KrakenRunner
- Object
- KrakenRunner
- KrakenMobile::Runner::MonkeyRunner
- Includes:
- Calabash::Android::Operations, CalabashAndroid::MonkeyHelper, CalabashAndroid::Operations, Protocol::FileProtocol
- Defined in:
- lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb
Instance Method Summary collapse
- #after_execution(process_number) ⇒ Object
-
#before_execution(process_number) ⇒ Object
——————————- Hooks ——————————-.
- #ensure_apks_signed ⇒ Object
-
#initialize(options) ⇒ MonkeyRunner
constructor
A new instance of MonkeyRunner.
-
#run_in_parallel ⇒ Object
——————————- Execution ——————————-.
- #run_tests(process_number, options) ⇒ Object
-
#set_environment_variables(process_number, general_apk) ⇒ Object
——————————- Helpers ——————————-.
Methods included from Protocol::FileProtocol
#build_scenario_id, #devices_ready_start, #devices_ready_to_finish, #end_setup, #feature_tags, #ordered_feature_tags, #readAnySignal, #readLastSignal, #readSignal, #readSignalWithKeyworkd, #start_setup, #writeSignal, #writeSignalToAll, #writeSignalToAnyDevice
Methods included from CalabashAndroid::MonkeyHelper
#enter_last_signal_in_random_input, #enter_text_in_random_input, #handle_random_action, #random_click, #random_touch_action, #run_intelligent_monkey, #run_monkey, #run_small_monkey, #send_random_signal
Methods included from CalabashAndroid::Operations
#channel_to_device_id, #install_app_with_calabash, #shutdown_kraken_test_server, #start_kraken_test_server_in_background, #uninstall_app_with_calabash
Constructor Details
#initialize(options) ⇒ MonkeyRunner
Returns a new instance of MonkeyRunner.
21 22 23 24 25 26 27 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 21 def initialize() super() default_runner = KrakenMobile::Constants::MONKEY @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}") end |
Instance Method Details
#after_execution(process_number) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 39 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_execution(process_number) ⇒ Object
Hooks
32 33 34 35 36 37 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 32 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 |
#ensure_apks_signed ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 101 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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 49 def run_in_parallel ensure_apks_signed devices_connected = @devices_manager.connected_devices threads = devices_connected.count puts "Running with #{threads} threads" test_results = Parallel.map_with_index( devices_connected, :in_threads => threads, :start => lambda { |device, index| before_execution(index) }, :finish => lambda { |device, index, _| after_execution(index) } ) do |device, index| run_tests(index, @options) end end |
#run_tests(process_number, options) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 68 def run_tests(process_number, ) set_environment_variables(process_number, [:apk_path]) puts "\n****** PROCESS #{process_number} STARTED ******\n\n" operations_module = Calabash::Android::Operations default_device = operations_module::Device.new(operations_module, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"]) install_app_with_calabash default_device.start_test_server_in_background run_intelligent_monkey "#@user#{process_number}", 20 default_device.shutdown_test_server uninstall_app_with_calabash puts "\n****** PROCESS #{process_number} COMPLETED ******\n\n" end |
#set_environment_variables(process_number, general_apk) ⇒ Object
Helpers
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/kraken-mobile/runners/calabash/monkey/monkey_runner.rb', line 84 def set_environment_variables process_number, general_apk 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 ENV["APP_PATH"] = apk_path ENV["TEST_APP_PATH"] = test_server_path(apk_path) ENV["AUTOTEST"] = '1' ENV["ADB_DEVICE_ARG"] = device.id ENV["DEVICE_INFO"] = device.model ENV["TEST_PROCESS_NUMBER"] = (process_number+1).to_s ENV["SCREENSHOT_PATH"] = "#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{device.screenshot_prefix}" ENV["PROTOCOL"] = KrakenMobile::Constants::FILE_PROTOCOL ENV["RUNNER"] = KrakenMobile::Constants::MONKEY ENV["CONFIG_PATH"] = @options[:config_path] if @options[:config_path] end |