Method: Snapshot::TestCommandGeneratorBase.find_device

Defined in:
snapshot/lib/snapshot/test_command_generator_base.rb

.find_device(device_name, os_version = ) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'snapshot/lib/snapshot/test_command_generator_base.rb', line 59

def find_device(device_name, os_version = Snapshot.config[:ios_version])
  # We might get this error message
  # > The requested device could not be found because multiple devices matched the request.
  #
  # This happens when you have multiple simulators for a given device type / iOS combination
  #   { platform:iOS Simulator, id:1685B071-AFB2-4DC1-BE29-8370BA4A6EBD, OS:9.0, name:iPhone 5 }
  #   { platform:iOS Simulator, id:A141F23B-96B3-491A-8949-813B376C28A7, OS:9.0, name:iPhone 5 }
  #
  simulators = FastlaneCore::DeviceManager.simulators
  # Sort devices with matching names by OS version, largest first, so that we can
  # pick the device with the newest OS in case an exact OS match is not available
  name_matches = simulators.find_all { |sim| sim.name.strip == device_name.strip }
                           .sort_by { |sim| Gem::Version.new(sim.os_version) }
                           .reverse
  return name_matches.find { |sim| sim.os_version == os_version } || name_matches.first
end