Reputation: 37581
I'm running some test code on the simulator but need to reset the simulator contents each time before runs to make sure the data stored and cached by the app during execution is removed before each re-run of the test cases.
Is there a way to do this from within the tests?
Upvotes: 0
Views: 586
Reputation: 1144
You can use simctl to reset your simulators from the command line, which you could use in a script in your actions to run before a test scheme, but not individual test cases. You need to install the xcode command line tools
to reset the simulator use :
xcrun simctl erase <simulator device id>
to get the device ID you use :
$ xcrun simctl list devices
== Devices ==
-- iOS 10.2 --
iPhone 5 (D226CF12-6782-4D7D-9C00-2D662CF4022C) (Shutdown)
iPhone 5s (34E0E0F8-3429-4D91-B038-ECF4FD0F3311) (Shutdown)
iPhone 6 (9C772A68-34E3-4F3F-981C-543DE6D5D985) (Shutdown)
iPhone 6 Plus (7848A50E-BFB5-4F19-BB31-4A56CA78AA2C) (Shutdown)
iPhone 6s (12CF89BA-C8B2-4837-B4EB-FB24DFF1622C) (Shutdown)
iPhone 6s Plus (3EE6CA84-8F12-4A5E-A31D-EF4BF3CCBDB2) (Shutdown)
iPhone 7 (1EB3CE5D-849C-491C-9CAA-5E97B1BD89CE) (Booted)
iPhone 7 Low Disk Space (6CCF4C7A-606B-40B7-A8D8-DF8B3CB119CB) (Shutdown)
iPhone 7 Plus (94FEFD36-6EFF-4762-BD21-79B1F958F6C6) (Shutdown)
iPhone SE (E8E8ECEB-34C0-44F0-B92E-57DCA91024F1) (Shutdown)
iPad Retina (0DA5BF39-3DC7-49B3-BE9B-2FA756FCA725) (Shutdown)
iPad Air (DAB9C2D3-8EBC-41DC-9C2D-0ECEC1D2FAE3) (Shutdown)
iPad Air 2 (1E2DA170-5C2E-413C-831B-FA65524643D3) (Shutdown)
iPad Pro (9.7 inch) (99F931A9-0708-4637-9294-6420DC7A149C) (Shutdown)
iPad Pro (12.9 inch) (08CD02EB-C44A-4183-961A-EED89FF1C225) (Shutdown)
-- tvOS 10.1 --
Apple TV 1080p (7EE393F2-C83E-467F-9802-3E5BFE7C2CA9) (Shutdown)
-- watchOS 3.1 --
Apple Watch - 38mm (B8969533-D7CD-462E-9E76-511C08E8CC8E) (Shutdown)
Apple Watch - 42mm (E16167D9-1007-438B-8812-CD97CE6ABECA) (Shutdown)
Apple Watch Series 2 - 38mm (F59C0BB1-B4D0-47DD-B927-1BFD78DD78C0) (Shutdown)
Apple Watch Series 2 - 42mm (7FE3AADD-94AB-46B9-A057-78F20F030999) (Shutdown)
Device IDs remain constant I think until they're deleted or recreated, it would probably be possible to retrieve the device id of the booted simulator using some scripting magik (which I haven't yet worked out), the current active simulator is always marked as (Booted)
You can also use simctl to create custom simulators, just use xcrun simctl to list all the stuff it does.
Upvotes: 1
Reputation: 11845
You could use LUA script to do this with your automated testing. Have a look at http://www.coronalabs.com/blog/2011/08/11/automated-testing-on-mobile-devices-part4/ for detailed instructions.
Basically you will have lua use events to reset it.
Upvotes: 0