Is there a way to call "Reset Content and Settings" of IOS simulator from appium?

I want to clear my simulator after a test complete. There is a function in IOS Simulator/Reset Content and Settings which cleans all the apps and reset the simulator. Is there a way to execute this method from appium method call.

I have not been successful doing this using Appium. However, I am successful doing this using the command line tool ‘simctl’. Use ‘simctl list’ to get a list of current simulators (you’ll need to parse out the UUID’s, see below), we store these in a ruby array, and then run 'simctl shutdown ’ against each simulator in the array, followed by 'simctl erase '. This is done before starting Appium on any tests that we run against a simulator. A bit crude, but very effective. We can also run this between test suites if necessary.

For getting the UUID’s, you’ll need to take this type of output:

== Devices ==
– iOS 7.1 –
iPhone 5 (998A88B4-7B75-48ED-84DC-59281B43C1BE) (Shutdown)
– iOS 8.1 –
– iOS 8.2 –
– iOS 8.3 –
iPhone 4s (37ED2AA6-3C9D-47EA-8F8D-6A4848E6BFD4) (Shutdown)
iPhone 6 (2DF52425-1A44-4B0D-B921-C692CEDF6BB8) (Shutdown)

And then grab only the long # in parens. That’s what you need to pass to simctl as the parameter.

Note that ‘simctl’ is probably not on your path. It’s located here: ‘/Applications/’.

I’m using this before I run my tests. So far, so good. It resets all simulators if that’s ok with you.

@taren7 Can you try with the flag --full-reset when starting appium server? I never tried that before but seems like it should work according to Appium document

Right. That --full-reset does it too.

I’ve recently switched over to --no-reset because I was having difficulties with iOS physical devices and wanted things consistent across the board with the ability to manually reset my simulator content when I wanted.

Depending on your goal, you’re right, go with --full-reset.

Good luck!

@tbao I tried using --full-reset that but the issue is it shuts down the simulator after the tests are complete, which is not acceptable in my current situation. Thanks for the advice though.

@wreed Thanks for your reply.
Simctl is a nice utility but I am still facing some issues:

  1. It does not execute the clear method if the device is in Booted state.
  2. Is there a way I can use these commands from Appium’s driver.executeScript() method, I am currently working on this but any leads will will helpful

I had suggested using the shutdown command as part of your solution, however, I feel like you must have realized that shutting down the simulator will kill your appium server as well. What if you stopped the Appium server between tests or test suites? This, of course, is a whole other topic that has been discussed on this board and the google group. You might try searching for more on that topic. Here is an example of what’s out there:!topic/appium-discuss/Z2L4sa2LAJI

Once you’ve sorted out stopping the server, the workflow should be something like:

simctl shutdown (just in case there was a problem shutting down)
simctl erase
start new appium server (which has the side effect of starting simulator)

we do it with osascript.example e.g. here:

Hey! I’m using noReset, but it’s not resenting the app, is there any other necessary capability that I can use together?

there is a fullReset capability…
set it to true to uninstall and reinstall the app automatically and to reset the device each time.
it is not necessarily the same cleanup as clicking Reset Content And Settings on iOS simulator.