In order to reset my app application between tests (without reseting the whole simulator because that makes the tests real slow) - I want to delete the NSUserDefaults plist for my application.
I want to run a shell script from inside my tests that deletes that file. The issues is that I need the SimulatorId in order to delete that file.
Any way to retrieve that?
Or is there any other way to reset your whole’s app state between tests without resetting the contents of the simulator - and thus making it really slow?
I do it by making a system call to instruments, executing the, ‘instruments -s devices’ command and then parsing the results based on the name of the simulator.
So in Ruby, something like:
def find_uuid(device_name)
devices = `/usr/bin/instruments -s devices`
device_list = devices.split("\n")
device_list.each do |device|
match_data = /(?<device_name>.*) \((?<os>.*)\) \[(?<uuid>.*)\]/.match(device)
next if match_data.nil?
next unless match_data[:device_name].eql? device_name
return match_data[:uuid]
end
end
By creating a simple file, ‘find_uuid.rb’ with a few extra parameters:
#!/usr/bin/ruby
device_name = ARGV[0]
def find_uuid(device_name)
devices = `/usr/bin/instruments -s devices`
device_list = devices.split("\n")
device_list.each do |device|
match_data = /(?<device_name>.*) \((?<os>.*)\) \[(?<uuid>.*)\]/.match(device)
next if match_data.nil?
next unless match_data[:device_name].eql? device_name
return match_data[:uuid]
end
end
puts find_uuid(device_name)
I get the following output from inputting a Simulator name I have:
What I’ve ended up doing though is writing the following Java piece of code that clears the NSUserDefaults for all installed simulators (since I don’t run any tests in parallel on multiple simulators):