Thanks for the help.
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):
private void clearIosUserDefaults() {
try {
String user = System.getenv("USER");
String removeUserDefaultsCommand = "find /Users/" + user + "/Library/Developer/CoreSimulator/Devices/ -path \"*/Preferences/com.mycompany.myapp.plist*\" -exec rm -rf {} \\;";
String[] shellCommand = new String[] {"/bin/sh", "-c", removeUserDefaultsCommand };
Runtime.getRuntime().exec(shellCommand);
} catch (IOException e) {
e.printStackTrace();
}
}
So far locally everything works great, hopefully I won’t run into permissions issues when I run this on Jenkins.
I also have a method that launches the application with clear local data:
public void launchAppWithClearedData() {
if (Platform.isOnIOS()) {
clearIosUserDefaults();
}
getDriver().launchApp();
}
This is kind of related to a different question that I’ve asked last week:
Now, using a @Before hook, all I do is call launchAppWithClearedData
and my app always runs from a well know state for each test (scenario).