Class: RunLoop::PhysicalDevice::IOSDeviceManager

Inherits:
LifeCycle
  • Object
show all
Defined in:
lib/run_loop/physical_device/ios_device_manager.rb

Constant Summary collapse

NOT_INSTALLED_EXIT_CODE =
2
DEFAULTS =
{
  install_timeout: RunLoop::Environment.ci? ? 240 : 120
}

Constants included from Shell

Shell::DEFAULT_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shell

run_shell_command, #run_shell_command

Methods included from Encoding

#transliterate

Constructor Details

#initialize(device) ⇒ IOSDeviceManager

Returns a new instance of IOSDeviceManager.



29
30
31
32
33
34
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 29

def initialize(device)
  super(device)

  # Expands the Frameworks.zip if necessary.
  RunLoop::DeviceAgent::Frameworks.instance.install
end

Class Method Details

.executable_pathObject

Path to tool.



25
26
27
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 25

def self.executable_path
  RunLoop::DeviceAgent::IOSDeviceManager.ios_device_manager
end

.tool_is_installed?Boolean

Is the tool installed?

Returns:

  • (Boolean)


20
21
22
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 20

def self.tool_is_installed?
  File.exist?(IOSDeviceManager.executable_path)
end

Instance Method Details

#app_installed?(app) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 53

def app_installed?(app)
  bundle_id = app
  if is_ipa?(app) || is_app?(app)
    bundle_id = app.bundle_identifier
  end

  args = [
    IOSDeviceManager.executable_path,
    "is-installed",
    bundle_id,
    "-d", device.udid
  ]

  options = { :log_cmd => true }
  hash = run_shell_command(args, options)

  exit_status = hash[:exit_status]

  if exit_status != 0 && exit_status != NOT_INSTALLED_EXIT_CODE
    raise_error_on_failure(
      RuntimeError,
      "Encountered an error checking if app is installed on device",
      app, device, hash
    )
  else
    RunLoop::log_debug("Took #{hash[:seconds_elapsed]} seconds to check " +
                         "app was installed")
    hash[:exit_status] == 0
  end
end

#can_reset_app_sandbox?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 116

def can_reset_app_sandbox?
  true
end

#ensure_newest_installed(app_or_ipa) ⇒ Object



88
89
90
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 88

def ensure_newest_installed(app_or_ipa)
  install_app_internal(app_or_ipa)
end

#install_app(app_or_ipa) ⇒ Object



84
85
86
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 84

def install_app(app_or_ipa)
  install_app_internal(app_or_ipa, ["--force"])
end

#raise_error_on_failure(error_klass, message, app, device, hash) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 36

def raise_error_on_failure(error_klass, message, app, device, hash)
  if hash[:exit_status] == 0
    true
  else
    raise error_klass, %Q[
    #{message}

  app: #{app}
     device: #{device}
exit status: #{hash[:exit_status]}

    #{hash[:out]}

]
  end
end

#reset_app_sandbox(app_or_ipa) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 120

def reset_app_sandbox(app_or_ipa)
  args = [IOSDeviceManager.executable_path,
          "clear-app-data",
          app_or_ipa.path,
          device.udid]

  options = { :log_cmd => true }
  hash = run_shell_command(args, options)

  raise_error_on_failure(
    ResetAppSandboxError,
    "Could not clear app data",
    app_or_ipa, device, hash
  )

  hash[:out]
end

#uninstall_app(app_or_ipa) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/run_loop/physical_device/ios_device_manager.rb', line 92

def uninstall_app(app_or_ipa)
  bundle_identifier = app_or_ipa.bundle_identifier
  if !app_installed?(bundle_identifier)
    return :was_not_installed
  end

  args = [
    IOSDeviceManager.executable_path,
    "uninstall",
    bundle_identifier,
    "-d", device.udid
  ]

  options = { :log_cmd => true }
  hash = run_shell_command(args, options)

  raise_error_on_failure(
    UninstallError,
    "Could not remove app from device",
    app_or_ipa, device, hash
  )
  hash[:out]
end