class FastlaneCore::Simulator

Public Class Methods

all() click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 220
def all
  return DeviceManager.simulators('iOS')
end
clear_cache() click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 251
def clear_cache
  @devices = nil
end
copy_logs(device, log_identity, logs_destination_dir) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 265
def copy_logs(device, log_identity, logs_destination_dir)
  logs_destination_dir = File.expand_path(logs_destination_dir)
  os_version = FastlaneCore::CommandExecutor.execute(command: 'sw_vers -productVersion', print_all: false, print_command: false)

  host_computer_supports_logarchives = Gem::Version.new(os_version) >= Gem::Version.new('10.12.0')
  device_supports_logarchives = Gem::Version.new(device.os_version) >= Gem::Version.new('10.0')

  are_logarchives_supported = device_supports_logarchives && host_computer_supports_logarchives
  if are_logarchives_supported
    copy_logarchive(device, log_identity, logs_destination_dir)
  else
    copy_logfile(device, log_identity, logs_destination_dir)
  end
end
delete_all() click to toggle source

Delete all simulators of this type

# File fastlane_core/lib/fastlane_core/device_manager.rb, line 242
def delete_all
  all.each(&:delete)
end
delete_all_by_version(os_version: nil) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 246
def delete_all_by_version(os_version: nil)
  return false unless os_version
  all.select { |device| device.os_version == os_version }.each(&:delete)
end
launch(device) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 255
def launch(device)
  return unless device.is_simulator

  simulator_path = File.join(Helper.xcode_path, 'Applications', 'Simulator.app')

  UI.verbose("Launching #{simulator_path} for device: #{device.name} (#{device.udid})")

  Helper.backticks("open -a #{simulator_path} --args -CurrentDeviceUDID #{device.udid}", print: FastlaneCore::Globals.verbose?)
end
reset(udid: nil, name: nil, os_version: nil) click to toggle source

Reset simulator by UDID or name and OS version Latter is useful when combined with -destination option of xcodebuild

# File fastlane_core/lib/fastlane_core/device_manager.rb, line 236
def reset(udid: nil, name: nil, os_version: nil)
  match = all.detect { |device| device.udid == udid || device.name == name && device.os_version == os_version }
  match.reset if match
end
reset_all() click to toggle source

Reset all simulators of this type

# File fastlane_core/lib/fastlane_core/device_manager.rb, line 225
def reset_all
  all.each(&:reset)
end
reset_all_by_version(os_version: nil) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 229
def reset_all_by_version(os_version: nil)
  return false unless os_version
  all.select { |device| device.os_version == os_version }.each(&:reset)
end
uninstall_app(app_identifier, device_type, device_udid) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 280
def uninstall_app(app_identifier, device_type, device_udid)
  UI.verbose("Uninstalling app '#{app_identifier}' from #{device_type}...")

  UI.message("Launch Simulator #{device_type}")
  Helper.backticks("xcrun instruments -w #{device_udid} &> /dev/null")

  UI.message("Uninstall application #{app_identifier}")
  Helper.backticks("xcrun simctl uninstall #{device_udid} #{app_identifier} &> /dev/null")
end

Private Class Methods

copy_logarchive(device, log_identity, logs_destination_dir) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 304
def copy_logarchive(device, log_identity, logs_destination_dir)
  require 'shellwords'

  logarchive_dst = File.join(logs_destination_dir, "system_logs-#{log_identity}.logarchive").shellescape
  FileUtils.rm_rf(logarchive_dst)
  FileUtils.mkdir_p(File.expand_path("..", logarchive_dst))
  command = "xcrun simctl spawn #{device.udid} log collect --output #{logarchive_dst} 2>/dev/null"
  FastlaneCore::CommandExecutor.execute(command: command, print_all: false, print_command: true)
end
copy_logfile(device, log_identity, logs_destination_dir) click to toggle source
# File fastlane_core/lib/fastlane_core/device_manager.rb, line 292
def copy_logfile(device, log_identity, logs_destination_dir)
  logfile_src = File.expand_path("~/Library/Logs/CoreSimulator/#{device.udid}/system.log")
  return unless File.exist?(logfile_src)

  FileUtils.mkdir_p(logs_destination_dir)
  logfile_dst = File.join(logs_destination_dir, "system-#{log_identity}.log")

  FileUtils.rm_f(logfile_dst)
  FileUtils.cp(logfile_src, logfile_dst)
  UI.success("Copying file '#{logfile_src}' to '#{logfile_dst}'...")
end