Class: RunLoop::CoreSimulator
- Inherits:
-
Object
- Object
- RunLoop::CoreSimulator
- Includes:
- Shell
- 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 180 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 : 180, :uninstall_app_timeout => RunLoop::Environment.ci? ? 120 : 180, :launch_app_timeout => RunLoop::Environment.ci? ? 120 : 180, :wait_for_state_timeout => RunLoop::Environment.ci? ? 120 : 180, :app_launch_retries => RunLoop::Environment.ci? ? 5 : 3 }
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(options = {}) ⇒ 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.
Methods included from Shell
run_shell_command, #run_shell_command
Methods included from Encoding
Constructor Details
#initialize(device, app, options = {}) ⇒ CoreSimulator
Returns a new instance of CoreSimulator.
392 393 394 395 396 397 398 399 |
# File 'lib/run_loop/core_simulator.rb', line 392 def initialize(device, app, ={}) @app = app @device = device @xcode = [:xcode] # 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?
543 544 545 546 547 548 549 550 |
# File 'lib/run_loop/core_simulator.rb', line 543 def app_is_installed? if installed_app_bundle_dir || simctl.app_container(device, app.bundle_identifier) true else false end 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.
529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/run_loop/core_simulator.rb', line 529 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.
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/run_loop/core_simulator.rb', line 482 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 tries = app_launch_retries RunLoop.log_debug("Trying #{tries} times to launch #{app.bundle_identifier} on #{device}") last_error = try_to_launch_app_n_times(tries) if last_error raise RuntimeError, %Q[ Could not launch #{app.bundle_identifier} on #{device} after trying #{tries} times: #{last_error}: #{last_error.} ] end wait_for_app_launch end |
#launch_simulator(options = {}) ⇒ Object
Launch the simulator indicated by device.
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/run_loop/core_simulator.rb', line 433 def launch_simulator(={}) = { :wait_for_stable => true }.merge() if !simulator_requires_relaunch? RunLoop.log_debug("Simulator is running and does not require a relaunch.") return end RunLoop::CoreSimulator.quit_simulator RunLoop::CoreSimulator.ensure_hardware_keyboard_connected(pbuddy) sim_keyboard.ensure_soft_keyboard_will_show sim_keyboard.ensure_keyboard_tutorial_disabled args = ['open', '-g', '-a', sim_app_path, '--args', '-CurrentDeviceUDID', device.udid, "-ConnectHardwareKeyboard", "0", "-DeviceBootTimeout", "120", # Yes, this is the argument even though it is not spelled correctly "-DetatchOnAppQuit", "0", "-DetachOnWindowClose", "0", "LAUNCHED_BY_RUN_LOOP"] 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 if [:wait_for_stable] device.simulator_wait_for_stable_state end elapsed = Time.now - start_time RunLoop.log_debug("Took #{elapsed} seconds to launch the simulator") true end |
#reset_app_sandbox ⇒ Object
Resets the app sandbox.
Does nothing if the app is not installed.
555 556 557 558 559 560 561 562 |
# File 'lib/run_loop/core_simulator.rb', line 555 def reset_app_sandbox return true if !app_is_installed? RunLoop::CoreSimulator.quit_simulator 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.
565 566 567 568 569 570 |
# File 'lib/run_loop/core_simulator.rb', line 565 def uninstall_app_and_sandbox return true if !app_is_installed? uninstall_app_with_simctl true end |