Module: Calabash::Cucumber::SimulatorAccessibility Deprecated

Included in:
Launcher
Defined in:
lib/calabash-cucumber/utils/simulator_accessibility.rb

Overview

Deprecated.

0.10.0 Replaced with RunLoop::SimControl

Public methods for common simulator tasks and private methods for enabling accessibility on the simulator.

Instance Method Summary collapse

Instance Method Details

#launch_simulatorObject

Launches the iOS Simulator indicated by ‘xcode-select` or `DEVELOPER_DIR`.



38
39
40
# File 'lib/calabash-cucumber/utils/simulator_accessibility.rb', line 38

def launch_simulator
  RunLoop::SimControl.new.launch_sim
end

#quit_simulatorObject

Quits the iOS Simulator.

ATM there can only be only simulator open at a time, so simply doing what the sim_launcher gem does:

“‘ def quit_simulator

`echo 'application "iPhone Simulator" quit' | osascript`

end “‘

works. I am not sure if we will ever be able to launch more than one simulator, but in case we can, this method will quit the simulator that is indicated by ‘xcode-select` or `DEVELOPER_DIR`.



33
34
35
# File 'lib/calabash-cucumber/utils/simulator_accessibility.rb', line 33

def quit_simulator
  RunLoop::SimControl.new.quit_sim
end

#reset_simulator_content_and_settingsObject

Resets the simulator content and settings. It is analogous to touching the menu item.

It works by deleting the following directories:

  • ~/Library/Application Support/iPhone Simulator/Library

  • ~/Library/Application Support/iPhone Simulator/Library/<sdk>

and relaunching the iOS Simulator which will recreate the Library directory and the latest SDK directory.



52
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
83
# File 'lib/calabash-cucumber/utils/simulator_accessibility.rb', line 52

def reset_simulator_content_and_settings
  quit_simulator
  sim_lib_path = File.join(simulator_app_support_dir(), 'Library')
  FileUtils.rm_rf(sim_lib_path)
  existing_simulator_support_sdk_dirs.each do |dir|
    FileUtils.rm_rf(dir)
  end

  launch_simulator

  # this is tricky because we need to wait for the simulator to recreate
  # the directories.  specifically, we need the Accessibility plist to be
  # exist so subsequent calabash launches will be able to enable
  # accessibility.
  #
  # the directories take ~3.0 - ~5.0 to create.
  counter = 0
  loop do
    break if counter == 80
    dirs = existing_simulator_support_sdk_dirs
    if dirs.count == 0
      sleep(0.2)
    else
      break if dirs.all? { |dir|
        plist = File.expand_path("#{dir}/Library/Preferences/com.apple.Accessibility.plist")
        File.exists?(plist)
      }
      sleep(0.2)
    end
    counter = counter + 1
  end
end