Skip to content

Commit

Permalink
leave only necessary params
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjar7 committed Dec 16, 2024
1 parent 0618cb3 commit 17ab1fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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: []
Expand All @@ -36,24 +39,25 @@ 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")
UI.success("Android emulator killed. Process finished.")
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)
Expand All @@ -77,42 +81,19 @@ 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",
description: "Device",
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",
Expand Down
38 changes: 1 addition & 37 deletions spec/maestro_orchestration_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 17ab1fd

Please sign in to comment.