diff --git a/lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb b/lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb index 41957a7..4b9aca2 100644 --- a/lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb +++ b/lib/fastlane/plugin/maestro_orchestration/actions/maestro_orchestration_android_action.rb @@ -7,7 +7,7 @@ module Fastlane module Actions class MaestroOrchestrationAndroidAction < Action def self.run(params) - required_params = [:emulator_name, :sdk_dir, :emulator_package, :emulator_device, :emulator_port, :maestro_flow_file] + required_params = [:emulator_package, :emulator_device, :maestro_flow_file] missing_params = required_params.select { |param| params[param].nil? } if missing_params.any? @@ -17,12 +17,15 @@ def self.run(params) raise "Missing required parameters: #{missing_params.join(', ')}" end + sdk_dir = "~/Library/Android/sdk" + adb = "#{sdk_dir}/platform-tools/adb" + Fastlane::Actions::AndroidEmulatorAction.run( - name: params[:emulator_name], - sdk_dir: params[:sdk_dir], + name: "Test_Emulator", + sdk_dir: sdk_dir, package: params[:emulator_package], device: params[:emulator_device], - port: params[:emulator_port], + port: "5554", demo_mode: false, cold_boot: true, additional_options: [] @@ -36,7 +39,6 @@ def self.run(params) UI.success("Finished Maestro tests on Android.") UI.message("Exit demo mode and kill Android emulator...") - adb = "#{params[:sdk_dir]}/platform-tools/adb" system("#{adb} shell am broadcast -a com.android.systemui.demo -e command exit") sleep(3) system("#{adb} emu kill") @@ -44,16 +46,18 @@ def self.run(params) end def self.demo_mode(params) + sdk_dir = "~/Library/Android/sdk" + UI.message("Checking and allowing demo mode on Android emulator...") - sh("#{params[:sdk_dir]}/platform-tools/adb shell settings put global sysui_demo_allowed 1") - sh("#{params[:sdk_dir]}/platform-tools/adb shell settings get global sysui_demo_allowed") + sh("#{sdk_dir}/platform-tools/adb shell settings put global sysui_demo_allowed 1") + sh("#{sdk_dir}/platform-tools/adb shell settings get global sysui_demo_allowed") UI.message("Setting demo mode commands...") - sh("#{params[:sdk_dir]}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command enter") - sh("#{params[:sdk_dir]}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1200") - sh("#{params[:sdk_dir]}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100") - sh("#{params[:sdk_dir]}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4") - sh("#{params[:sdk_dir]}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4") + sh("#{sdk_dir}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command enter") + sh("#{sdk_dir}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1200") + sh("#{sdk_dir}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command battery -e level 100") + sh("#{sdk_dir}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4") + sh("#{sdk_dir}/platform-tools/adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4") end def self.build_and_install_android_app(params) @@ -77,28 +81,12 @@ def self.description def self.available_options [ - FastlaneCore::ConfigItem.new( - key: :sdk_dir, - env_name: "MAESTRO_ANDROID_SDK_DIR", - description: "Path to the Android SDK DIR", - optional: false, - 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: :emulator_package, env_name: "MAESTRO_AVD_PACKAGE", description: "The selected system image of the emulator", optional: false ), - FastlaneCore::ConfigItem.new( - key: :emulator_name, - env_name: "MAESTRO_AVD_NAME", - description: "Name of the AVD", - default_value: "fastlane", - optional: false - ), FastlaneCore::ConfigItem.new( key: :emulator_device, env_name: "MAESTRO_AVD_DEVICE", @@ -106,13 +94,6 @@ def self.available_options default_value: "Nexus 5", optional: false ), - FastlaneCore::ConfigItem.new( - key: :emulator_port, - env_name: "MAESTRO_AVD_PORT", - description: "Port of the emulator", - default_value: "5554", - optional: false - ), FastlaneCore::ConfigItem.new( key: :location, env_name: "MAESTRO_AVD_LOCATION", diff --git a/spec/maestro_orchestration_action_spec.rb b/spec/maestro_orchestration_action_spec.rb index 33018b0..fa00d6e 100644 --- a/spec/maestro_orchestration_action_spec.rb +++ b/spec/maestro_orchestration_action_spec.rb @@ -54,30 +54,16 @@ describe 'Parameter Passing' do it "makes sure that all the parameters are passed" do valid_params = { - emulator_name: "Pixel_3_API_29", - sdk_dir: "/Users/username/Library/Android/sdk", package: "system-images;android-29;google_apis;x86", device: "Nexus 5X", - port: "5554", flow_file: "flows.yaml" } - %i[emulator_name sdk_dir package device port flow_file].each do |key| + %i[package device flow_file].each do |key| expect(valid_params[key]).not_to be_nil end end - it 'throws error if emulator_name is not provided' do - invalid_params = { - sdk_dir: "/Users/username/Library/Android/sdk", - emulator_package: "system-images;android-29;google_apis;x86", - emulator_device: "Nexus 5X", - emulator_port: "5554", - maestro_flow_file: "flows.yaml" - } - expect { Fastlane::Actions::MaestroOrchestrationAndroidAction.run(invalid_params) }.to raise_error("Missing required parameters: emulator_name") - end - it 'throws error if emulator_device is not provided' do invalid_params = { emulator_name: "Pixel_3_API_29", @@ -89,17 +75,6 @@ expect { Fastlane::Actions::MaestroOrchestrationAndroidAction.run(invalid_params) }.to raise_error("Missing required parameters: emulator_device") end - it 'throws error if skd_dir is not provided' do - invalid_params = { - emulator_name: "Pixel_3_API_29", - emulator_package: "system-images;android-29;google_apis;x86", - emulator_device: "Nexus 5X", - emulator_port: "5554", - maestro_flow_file: "flows.yaml" - } - expect { Fastlane::Actions::MaestroOrchestrationAndroidAction.run(invalid_params) }.to raise_error("Missing required parameters: sdk_dir") - end - it 'throws error if emulator_package is not provided' do invalid_params = { emulator_name: "Pixel_3_API_29", @@ -111,17 +86,6 @@ expect { Fastlane::Actions::MaestroOrchestrationAndroidAction.run(invalid_params) }.to raise_error("Missing required parameters: emulator_package") end - it 'throws error if emulator_port is not provided' do - invalid_params = { - emulator_name: "Pixel_3_API_29", - sdk_dir: "/Users/username/Library/Android/sdk", - emulator_package: "system-images;android-29;google_apis;x86", - emulator_device: "Nexus 5X", - maestro_flow_file: "flows.yaml" - } - expect { Fastlane::Actions::MaestroOrchestrationAndroidAction.run(invalid_params) }.to raise_error("Missing required parameters: emulator_port") - end - it 'throws error if maestro_flow_file is not provided' do invalid_params = { emulator_name: "Pixel_3_API_29",