Class: Snapshot::SimulatorLauncherBase
- Inherits:
-
Object
- Object
- Snapshot::SimulatorLauncherBase
show all
- Defined in:
- snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_media(device_types, media_type, paths) ⇒ Object
pass an array of device types.
-
#copy_simulator_logs(device_names, language, locale, launch_arguments) ⇒ Object
-
#erase_simulator(device_type) ⇒ Object
-
#initialize(launcher_configuration: nil) ⇒ SimulatorLauncherBase
constructor
A new instance of SimulatorLauncherBase.
-
#interface_style(device_type, dark_mode) ⇒ Object
-
#localize_simulator(device_type, language, locale) ⇒ Object
-
#prepare_directories_for_launch(language: nil, locale: nil, launch_arguments: nil) ⇒ Object
-
#prepare_for_launch(device_types, language, locale, launch_arguments) ⇒ Object
-
#prepare_simulators_for_launch(device_types, language: nil, locale: nil) ⇒ Object
-
#uninstall_app(device_type) ⇒ Object
Constructor Details
#initialize(launcher_configuration: nil) ⇒ SimulatorLauncherBase
Returns a new instance of SimulatorLauncherBase.
17
18
19
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 17
def initialize(launcher_configuration: nil)
@launcher_config = launcher_configuration
end
|
Instance Attribute Details
#collected_errors ⇒ Object
Returns the value of attribute collected_errors.
11
12
13
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 11
def collected_errors
@collected_errors
end
|
#current_number_of_retries_due_to_failing_simulator ⇒ Object
The number of times we failed on launching the simulator… sigh
14
15
16
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 14
def current_number_of_retries_due_to_failing_simulator
@current_number_of_retries_due_to_failing_simulator
end
|
#launcher_config ⇒ Object
Returns the value of attribute launcher_config.
15
16
17
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 15
def launcher_config
@launcher_config
end
|
Instance Method Details
pass an array of device types
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 74
def add_media(device_types, media_type, paths)
media_type = media_type.to_s
device_types.each do |device_type|
UI.verbose("Adding #{media_type}s to #{device_type}...")
device_udid = TestCommandGenerator.device_udid(device_type)
UI.message("Launch Simulator #{device_type}")
Helper.backticks("xcrun instruments -w #{device_udid} &> /dev/null")
paths.each do |path|
UI.message("Adding '#{path}'")
output = Helper.backticks("xcrun simctl addmedia #{device_udid} #{path.shellescape} &> /dev/null")
if output.include?('usage: simctl')
Helper.backticks("xcrun simctl add#{media_type} #{device_udid} #{path.shellescape} &> /dev/null")
end
end
end
end
|
#copy_simulator_logs(device_names, language, locale, launch_arguments) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 142
def copy_simulator_logs(device_names, language, locale, launch_arguments)
return unless launcher_config.output_simulator_logs
detected_language = locale || language
language_folder = File.join(launcher_config.output_directory, detected_language)
device_names.each do |device_name|
device = TestCommandGeneratorBase.find_device(device_name)
components = [launch_arguments].delete_if { |a| a.to_s.length == 0 }
UI.("Collecting system logs #{device_name} - #{language}")
log_identity = Digest::MD5.hexdigest(components.join("-"))
FastlaneCore::Simulator.copy_logs(device, log_identity, language_folder)
end
end
|
#erase_simulator(device_type) ⇒ Object
107
108
109
110
111
112
113
114
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 107
def erase_simulator(device_type)
UI.verbose("Erasing #{device_type}...")
device_udid = TestCommandGenerator.device_udid(device_type)
UI.important("Erasing #{device_type}...")
`xcrun simctl erase #{device_udid} &> /dev/null`
end
|
#interface_style(device_type, dark_mode) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 130
def interface_style(device_type, dark_mode)
device_udid = TestCommandGenerator.device_udid(device_type)
if device_udid
plist = {
UserInterfaceStyleMode: (dark_mode ? 2 : 1)
}
UI.message("Setting interface style #{device_type} (UserInterfaceStyleMode=#{dark_mode})")
plist_path = "#{ENV['HOME']}/Library/Developer/CoreSimulator/Devices/#{device_udid}/data/Library/Preferences/com.apple.uikitservices.userInterfaceStyleMode.plist"
File.write(plist_path, Plist::Emit.dump(plist))
end
end
|
#localize_simulator(device_type, language, locale) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 116
def localize_simulator(device_type, language, locale)
device_udid = TestCommandGenerator.device_udid(device_type)
if device_udid
locale ||= language.sub("-", "_")
plist = {
AppleLocale: locale,
AppleLanguages: [language]
}
UI.message("Localizing #{device_type} (AppleLocale=#{locale} AppleLanguages=[#{language}])")
plist_path = "#{ENV['HOME']}/Library/Developer/CoreSimulator/Devices/#{device_udid}/data/Library/Preferences/.GlobalPreferences.plist"
File.write(plist_path, Plist::Emit.dump(plist))
end
end
|
#prepare_directories_for_launch(language: nil, locale: nil, launch_arguments: nil) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 34
def prepare_directories_for_launch(language: nil, locale: nil, launch_arguments: nil)
screenshots_path = TestCommandGenerator.derived_data_path
FileUtils.rm_rf(File.join(screenshots_path, "Logs"))
FileUtils.rm_rf(screenshots_path) if launcher_config.clean
FileUtils.mkdir_p(screenshots_path)
FileUtils.mkdir_p(CACHE_DIR)
FileUtils.mkdir_p(SCREENSHOTS_DIR)
File.write(File.join(CACHE_DIR, "language.txt"), language)
File.write(File.join(CACHE_DIR, "locale.txt"), locale || "")
File.write(File.join(CACHE_DIR, "snapshot-launch_arguments.txt"), launch_arguments.last)
end
|
#prepare_for_launch(device_types, language, locale, launch_arguments) ⇒ Object
29
30
31
32
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 29
def prepare_for_launch(device_types, language, locale, launch_arguments)
prepare_directories_for_launch(language: language, locale: locale, launch_arguments: launch_arguments)
prepare_simulators_for_launch(device_types, language: language, locale: locale)
end
|
#prepare_simulators_for_launch(device_types, language: nil, locale: nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 48
def prepare_simulators_for_launch(device_types, language: nil, locale: nil)
Snapshot.kill_simulator `xcrun simctl shutdown booted &> /dev/null`
Fixes::SimulatorZoomFix.patch
Fixes::HardwareKeyboardFix.patch
device_types.each do |type|
if launcher_config.erase_simulator || launcher_config.localize_simulator || !launcher_config.dark_mode.nil?
erase_simulator(type)
if launcher_config.localize_simulator
localize_simulator(type, language, locale)
end
unless launcher_config.dark_mode.nil?
interface_style(type, launcher_config.dark_mode)
end
elsif launcher_config.reinstall_app
uninstall_app(type)
end
end
end
|
#uninstall_app(device_type) ⇒ Object
100
101
102
103
104
105
|
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb', line 100
def uninstall_app(device_type)
launcher_config.app_identifier ||= UI.input("App Identifier: ")
device_udid = TestCommandGenerator.device_udid(device_type)
FastlaneCore::Simulator.uninstall_app(launcher_config.app_identifier, device_type, device_udid)
end
|