Class: Fastlane::Actions::LaunchSimulatorAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/maestro/actions/launch_simulator.rb

Class Method Summary collapse

Class Method Details

.authorsObject



58
59
60
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 58

def self.authors
  ['Marc Bormeth']
end

.available_optionsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 70

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :app_path,
                                  env_name: "FL_APP_PATH",
                                  description: "Path to the .app file for simulators",
                                  type: String,
                                  default_value: ""),
    FastlaneCore::ConfigItem.new(key: :ios_version,
                                  description: "iOS runtime version to be used for the simulator",
                                  short_option: "-i", # same as for scan
                                  optional: true,
                                  default_value: ''),
    FastlaneCore::ConfigItem.new(key: :language,
                                  description: "The language which should be used",
                                  short_option: "-g", # same as for scan
                                  type: String,
                                  default_value: 'en-US',
                                  optional: true),
    FastlaneCore::ConfigItem.new(key: :device_name,
                                  short_option: "-a", # same as for scan
                                  optional: false,
                                  type: String,
                                  env_name: "MAESTRO_DEVICE",
                                  description: "The name of the simulator type you want to run tests on (e.g. 'iPhone 14' or 'iPhone SE (2nd generation) (14.5)')")
  ]
end

.descriptionObject



54
55
56
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 54

def self.description
  'Prepares an iOS simulator for Maestro testing'
end

.detailsObject



66
67
68
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 66

def self.details
  'Creates a simulator for the given `:ios_version` and `:device`. \nAfterwards, it patches the language, locale & status bar and installs the given :app on it.'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 97

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  [:ios].include?(platform)
end

.return_valueObject



62
63
64
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 62

def self.return_value
  "Object of [SimCtl::Device](https://www.rubydoc.info/gems/simctl/SimCtl/Device)"
end

.run(params) ⇒ Object



8
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
47
48
49
50
51
52
# File 'lib/fastlane/plugin/maestro/actions/launch_simulator.rb', line 8

def self.run(params)
  device_type = SimCtl.devicetype(name: params[:device_name])
  device_name = "Maestro - #{params[:device_name]}"

  runtime_name = ''
  if params[:ios_version].nil? || params[:ios_version].empty?
    runtime_name = SimCtl.list_runtimes()[0].name
  else
    runtime_name = "iOS #{params[:ios_version]}"
  end
  runtime = SimCtl.runtime(name: runtime_name)
  UI.message("Creating device #{device_name} with runtime #{runtime_name}")
  device = SimCtl.create_device(device_name, device_type, runtime)

  device.boot

  UI.message("Waiting for device to boot")
  device.wait { |d| d.state == :booted }

  unless params[:language].nil? || params[:language].empty?
    UI.message("Setting device language to #{params[:language]}")
    device.settings.set_language(params[:language])
    device.settings.set_locale(params[:language])
  end

  UI.message("Patching device settings for tests")
  time = Time.new(2007, 1, 9, 9, 41, 0)
  device.status_bar.clear
  device.status_bar.override(
    time: time.iso8601,
    dataNetwork: '5g',
    wifiMode: 'active',
    cellularMode: 'active',
    batteryState: 'charging',
    batteryLevel: 100
  )
  device.settings.disable_keyboard_helpers

  device.launch

  UI.message("Installing app #{params[:app_path]} on the simulator")
  device.install(params[:app_path])

  return device
end