simnik
simnik

Reputation: 483

Setting up Simulator for Automated UITesting

I need to setup my Simulators for Automated UITesting. Especially removing Autocorrection, Spellchecking, Prediction etc from the Keyboard.

I am doing that for one Simulator like that:

plutil -replace KeyboardAutocapitalization -bool NO -- ~/Library/Developer/CoreSimulator/Devices/319FF855-F54C-4BB7-BDED-F0CC4B1FF8FC/data/Library/Preferences/com.apple.Preferences.plist

The problem with that is, when the Tests run on another Device, it won't setup the simulator since the UUID is hardcoded.

I also am able to a booted / selected Simulator like this:

currentUUID="$(xcrun simctl list devices | grep "iPhone 7 (" | egrep -o -i "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")"

where I have to put in iPhone 7 ( in order to get the UUIDof only the iPhone 7 and not the 7+. This also only works if I really selected the iPhone 7 as a Simulator in Xcode before. Another way of doing it is to replace the iPhone 7 ( with booted.

But in order for this to work, the script needs the Simulator to already run. And when it does already run, changing the plist files won't actually update the settings on the Simulator.

How would I be able to launch a Simulator and then grab it's UUID before setting it up?

Thank you.

Upvotes: 1

Views: 538

Answers (1)

Bartosz Janda
Bartosz Janda

Reputation: 1661

plu has created a simctl gem which is able to manipulate simulators. It can create, delete, boot device and do much more. One interesting feature is disabling keyboard helpers. If you are using Fastlane you can create new private lane which will disable keyboard helpers for all.

To install this gem use:

[sudo] gem install simctl 

In the Fastfile add this lane:

private_lane :disable_keyboard_helpers do
  require "simctl"
  SimCtl.list_devices.each do |d| 
    d.settings.disable_keyboard_helpers
  end
end

Now in your test lane, you can use disable_keyboard_helpers like this one:

lane :test do |options|
  disable_keyboard_helpers
  scan
end

If you are not using Fastlane you can still use simctl by executing Ruby command directly:

ruby -e "require 'simctl'; SimCtl.list_devices.each { |d| d.settings.disable_keyboard_helpers }"

Upvotes: 5

Related Questions