Class: Fastlane::Actions::MaestroOrchestrationAndroidAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::MaestroOrchestrationAndroidAction
- Defined in:
- lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb
Class Method Summary collapse
- .available_options ⇒ Object
- .demo_mode(params) ⇒ Object
- .description ⇒ Object
- .install_android_app(params) ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(params) ⇒ Object
Class Method Details
.available_options ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb', line 89 def self. [ FastlaneCore::ConfigItem.new( key: :sdk_dir, env_name: "MAESTRO_ANDROID_SDK_DIR", description: "Path to the Android SDK DIR", default_value: ENV["ANDROID_HOME"] || ENV["ANDROID_SDK_ROOT"] || "~/Library/Android/sdk", optional: true, verify_block: proc do |value| UI.user_error!("No ANDROID_SDK_DIR given, pass using `sdk_dir: 'sdk_dir'`") unless value && !value.empty? end ), FastlaneCore::ConfigItem.new( key: :maestro_flow_file, env_name: "MAESTRO_ANDROID_FLOW_FILE", description: "The path to the Maestro flow YAML file", optional: false, type: String ), FastlaneCore::ConfigItem.new( key: :clear_maestro_logs, env_name: "MAESTRO_CLEAR_LOGS", description: "If true, clears all previous Maestro logs before running tests", type: Boolean, default_value: true, optional: true ) ] end |
.demo_mode(params) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb', line 48 def self.demo_mode(params) adb = Helper::AdbHelper.new adb.load_all_devices serial = adb.devices.first.serial UI.("Checking and allowing demo mode on Android emulator...") adb.trigger(command: "shell settings put global sysui_demo_allowed 1", serial: serial) adb.trigger(command: "shell settings get global sysui_demo_allowed", serial: serial) UI.("Setting demo mode commands...") adb.trigger(command: "shell am broadcast -a com.android.systemui.demo -e command enter", serial: serial) adb.trigger(command: "shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1200", serial: serial) adb.trigger(command: "shell am broadcast -a com.android.systemui.demo -e command battery -e level 100", serial: serial) end |
.description ⇒ Object
85 86 87 |
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb', line 85 def self.description "Boots an Android emulator, builds the app, installs it, and runs Maestro tests" end |
.install_android_app(params) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb', line 63 def self.install_android_app(params) UI.("Installing Android app...") adb = Helper::AdbHelper.new adb.load_all_devices serial = adb.devices.first.serial UI.("Generating 'assembleRelease' build...") # Trigger the 'assembleRelease' build system("./gradlew assembleRelease") # After building, try to find the APK file in the release output directory apk_path = Dir["app/build/outputs/apk/release/*.apk"].first # If still not found after building, raise an error if apk_path.nil? UI.user_error!("Error: APK file not found in build outputs even after running assembleRelease.") end UI.("Found APK file at: #{apk_path}") adb.trigger(command: "install -r '#{apk_path}'", serial: serial) UI.success("APK installed on Android emulator.") end |
.is_supported?(platform) ⇒ Boolean
119 120 121 |
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb', line 119 def self.is_supported?(platform) platform == :android end |
.run(params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb', line 9 def self.run(params) required_params = [:maestro_flow_file] missing_params = required_params.select { |param| params[param].nil? } if missing_params.any? missing_params.each do |param| UI.error("Missing parameter: #{param}") end raise "Missing required parameters: #{missing_params.join(', ')}" end Helper::MaestroOrchestrationHelper.clear_maestro_logs if params[:clear_maestro_logs] adb = Helper::AdbHelper.new sleep(5) # Give time emulator to boot demo_mode(params) install_android_app(params) UI.("Running Maestro tests on Android...") devices = adb.load_all_devices if devices.empty? UI.("No running emulators found.") else sleep(2) UI.("Devices: #{devices}") devices.each do |device| sh("maestro --device #{device.serial} test #{params[:maestro_flow_file]}") UI.success("Finished Maestro tests on Android.") end end UI.("Exit demo mode and kill Android emulator...") adb.trigger(command: "shell am broadcast -a com.android.systemui.demo -e command exit", serial: devices.first.serial) sleep(5) adb.trigger(command: "emu kill", serial: devices.first.serial) UI.success("Android emulator killed. Process finished.") end |