Class: RunLoop::CoreSimulator
- Inherits:
-
Object
- Object
- RunLoop::CoreSimulator
- Defined in:
- lib/run_loop/core_simulator.rb
Overview
A class to manage interactions with CoreSimulators.
Constant Summary collapse
- DEFAULT_OPTIONS =
These options control various aspects of an app’s life cycle on the iOS Simulator.
You can override these values if they do not work in your environment.
For cucumber users, the best place to override would be in your features/support/env.rb.
For example:
{ # In most cases 30 seconds is a reasonable amount of time to wait for an # install. When testing larger apps, on slow machines, or in CI, this # value may need to be higher. 120 is the default for CI. :install_app_timeout => RunLoop::Environment.ci? ? 120 : 30, :uninstall_app_timeout => RunLoop::Environment.ci? ? 120 : 30, :launch_app_timeout => RunLoop::Environment.ci? ? 120 : 30, :wait_for_state_timeout => RunLoop::Environment.ci? ? 120 : 30 }
Instance Method Summary collapse
-
#app_is_installed? ⇒ Boolean
Is this app installed?.
-
#initialize(device, app, options = {}) ⇒ CoreSimulator
constructor
A new instance of CoreSimulator.
-
#install ⇒ Object
Install the app.
-
#launch ⇒ Object
Launch the app on the simulator.
-
#launch_simulator ⇒ Object
Launch the simulator indicated by device.
-
#reset_app_sandbox ⇒ Object
Resets the app sandbox.
-
#uninstall_app_and_sandbox ⇒ Object
Uninstalls the app and clears the sandbox.
Constructor Details
#initialize(device, app, options = {}) ⇒ CoreSimulator
Returns a new instance of CoreSimulator.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/run_loop/core_simulator.rb', line 256 def initialize(device, app, ={}) defaults = { :quit_sim_on_init => true } merged = defaults.merge() @app = app @device = device @xcode = merged[:xcode] if merged[:quit_sim_on_init] RunLoop::CoreSimulator.quit_simulator end # stdio.pipe - can cause problems finding the SHA of a simulator rm_instruments_pipe end |
Instance Method Details
#app_is_installed? ⇒ Boolean
Is this app installed?
384 385 386 |
# File 'lib/run_loop/core_simulator.rb', line 384 def app_is_installed? !installed_app_bundle_dir.nil? end |
#install ⇒ Object
Install the app.
-
If the app is not installed, it is installed.
-
Does nothing, if the app is the same as the one that is installed.
-
Installs the app if it is different from the installed app.
The app sandbox is not touched.
370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/run_loop/core_simulator.rb', line 370 def install installed_app_bundle = installed_app_bundle_dir # App is not installed. Use simctl interface to install. if !installed_app_bundle installed_app_bundle = install_app_with_simctl else ensure_app_same end installed_app_bundle end |
#launch ⇒ Object
Launch the app on the simulator.
-
If the app is not installed, it is installed.
-
If the app is different from the app that is installed, it is installed.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/run_loop/core_simulator.rb', line 332 def launch install # If the app is the same, install will not launch the simulator. # In order to launch the app, the simulator needs to be running. # launch_simulator ensures that the sim is launched and will not # relaunch it. launch_simulator args = ['simctl', 'launch', device.udid, app.bundle_identifier] timeout = DEFAULT_OPTIONS[:launch_app_timeout] hash = xcrun.exec(args, log_cmd: true, timeout: timeout) exit_status = hash[:exit_status] if exit_status != 0 RunLoop.log_error(hash[:out]) raise RuntimeError, "Could not launch #{app.bundle_identifier} on #{device}" end = { :timeout => 10, :raise_on_timeout => true } RunLoop::ProcessWaiter.new(app.executable_name, ).wait_for_any device.simulator_wait_for_stable_state true end |
#launch_simulator ⇒ Object
Launch the simulator indicated by device.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/run_loop/core_simulator.rb', line 289 def launch_simulator if running_simulator_pid != nil # There is a running simulator. # Did we launch it? if running_simulator_pid == RunLoop::CoreSimulator.simulator_pid # Nothing to do, we already launched the simulator. return else # We did not launch this simulator; quit it. RunLoop::CoreSimulator.quit_simulator end end args = ['open', '-g', '-a', sim_app_path, '--args', '-CurrentDeviceUDID', device.udid] RunLoop.log_debug("Launching #{device} with:") RunLoop.log_unix_cmd("xcrun #{args.join(' ')}") start_time = Time.now pid = Process.spawn('xcrun', *args) Process.detach(pid) = { :timeout => 5, :raise_on_timeout => true } RunLoop::ProcessWaiter.new(sim_name, ).wait_for_any device.simulator_wait_for_stable_state elapsed = Time.now - start_time RunLoop.log_debug("Took #{elapsed} seconds to launch the simulator") # Keep track of the pid so we can know if we have already launched this sim. RunLoop::CoreSimulator.simulator_pid = running_simulator_pid true end |
#reset_app_sandbox ⇒ Object
Resets the app sandbox.
Does nothing if the app is not installed.
391 392 393 394 395 396 397 |
# File 'lib/run_loop/core_simulator.rb', line 391 def reset_app_sandbox return true if !app_is_installed? RunLoop::CoreSimulator.wait_for_simulator_state(device, "Shutdown") reset_app_sandbox_internal end |
#uninstall_app_and_sandbox ⇒ Object
Uninstalls the app and clears the sandbox.
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/run_loop/core_simulator.rb', line 400 def uninstall_app_and_sandbox return true if !app_is_installed? launch_simulator args = ['simctl', 'uninstall', device.udid, app.bundle_identifier] timeout = DEFAULT_OPTIONS[:uninstall_app_timeout] xcrun.exec(args, log_cmd: true, timeout: timeout) device.simulator_wait_for_stable_state true end |