bin/calabash-ios-sim.rb in calabash-cucumber-0.17.1 vs bin/calabash-ios-sim.rb in calabash-cucumber-0.18.0

- old
+ new

@@ -1,7 +1,8 @@ require 'calabash-cucumber/utils/simulator_accessibility' require 'calabash-cucumber/utils/logging' +require "calabash-cucumber/environment" require 'run_loop' include Calabash::Cucumber::Logging include Calabash::Cucumber::SimulatorAccessibility @@ -60,49 +61,102 @@ end def calabash_sim_locale(args) - prefs_path = File.expand_path("#{@script_dir}/data/.GlobalPreferences.plist") - plist = CFPropertyList::List.new(:file => prefs_path) - hash = CFPropertyList.native_types(plist.value) + if args.length != 2 + puts %Q{ +Usage: +$ calabash-ios sim locale < language code > < locale code > - if args.length == 0 - print_usage - puts "Options: \n" - puts hash['AppleLanguages'].join("\n") - exit 0 - end - lang = args.shift - reg = nil - if args.length == 1 - reg = args.shift - end +Examples: - langs = hash['AppleLanguages'] - lang_index = langs.find_index { |l| l == lang } +# French language and locale +$ calabash-ios sim locale fr fr - if lang_index.nil? - puts "Unable to find #{lang}..." - puts "Options:\n#{langs.join("\n")}" - exit 0 +# Swiss French with Swiss German locale +$ calabash-ios sim locale fr-CH de_CH + +By default, this method will change the default simulator for the active +Xcode version. If you want to target an alternative simulator, set the +DEVICE_TARGET environment variable. + +$ DEVICE_TARGET="iPhone 6 (9.2)" calabash-ios sim locale en-US en_US +$ DEVICE_TARGET=B9BCAD64-1624-4277-9361-40EFFBD7C67F calabash-ios sim locale de de + +This operation will quit and reset the simulator. +} + return false end - langs[0], langs[lang_index] = langs[lang_index], langs[0] + language = args[0] + locale = args[1] + device_target = Calabash::Cucumber::Environment.device_target + default_target = RunLoop::Core.default_simulator - if reg - hash['AppleLocale'] = reg + target = device_target || default_target + + device = RunLoop::Device.device_with_identifier(target) + + if device.nil? + if target == device_target + puts %Q{ +Could not find simulator matching: + +DEVICE_TARGET=#{device_target} + +Check the output of: + +$ xcrun instruments -s devices + +for a list of available simulators. +} + else + puts %Q{ +Could not find the default simulator. Make sure that you have +the right version of run_loop installed for your Xcode version. +} + end + + return false end - res_plist = CFPropertyList::List.new - res_plist.value = CFPropertyList.guess(hash) - dirs = Dir.glob(File.join(File.expand_path("~/Library"), "Application Support", "iPhone Simulator", "*.*", "Library", "Preferences")) - dirs.each do |sim_pref_dir| - res_plist.save("#{sim_pref_dir}/.GlobalPreferences.plist", CFPropertyList::List::FORMAT_BINARY) + + if device.physical_device? + puts %Q{ +This tool is for simulators only. + +#{target} is a physical device. +} + return false end + RunLoop::CoreSimulator.set_language(device, language) + RunLoop::CoreSimulator.set_locale(device, locale) + puts %Q{ +Set langauge to: '#{language}' and locale to: '#{locale}'. + +Don't forget to launch your app with these options: + +options = { + args = [ + "-AppleLanguages", "(#{language})", + "-AppleLocale", "#{locale}" + ] +} + +to ensure that your app launches with the correct primary langauge. + +Examples: + +* https://github.com/calabash/calabash-ios/wiki/Changing-Locale-and-Language +* https://github.com/calabash/Permissions/blob/master/features/0x/support/01_launch.rb + +SUCCESS! +} + true end def calabash_sim_device(args) quit_simulator