Detox: Add a way to clean AsyncStorage

Created on 20 Apr 2017  路  13Comments  路  Source: wix/Detox

That's an awesome library, thank you!
But I cannot find out a way to clean AsyncStorage. Is there any?

questiostack overflow

All 13 comments

Hey @huston007 , thanks.

What about uninstalling and installing the app again ? It should have the same effect.

device.uninstallApp();
device.installApp();

Yes, thank you! Looks like await device.relaunchApp({delete: true}); will do the same, but it is a little bit overhead to reinstall app for every test if I just need it to start clean.

I'm trying to find a command for fbsimctl which does this, don't you know any? If there are such command, I would do like
await device._fbsimctl._execFbsimctlCommand({args:${device._simulatorUdid} cleanstorage});

Have found docs here

Correct me if I'm wrong, but I don't think there is such an option in fbsimctl nor in simctl. There's no easy way deleting just app data in iOS.
If you find anything, please bring it to our attention.

Well, I did a quick research around fbsimctl, xcodebuild and xcrun simctl and yes, there are no such option. So I'll be reinstalling app again and again, no problem : )

If somebody interested, there is a way to clear keychain
await device.deviceDriver._fbsimctl._execFbsimctlCommand({args:${device._deviceId} clear_keychain});

From what I see in the docs clear_keychain only clears the keychain, it will log you out from your app but it will not delete all storage.

@rotemmiz yes you're right, I just left it here because it was enough to me to just clear keychain in some case. It may be helpful to somebody : )

await device.deviceDriver._applesimutils._execAppleSimUtils({
      args: `--simulator "${device._deviceId}" --clearKeychain`,
    });

I'm also interested in clearing AsyncStorage for both IOS & Android. Reinstalling the app degrades tests performance (. Still no other ways to do it?

For now, I'm using launchUrls to clean/setup AsyncStorage to the required state.

@vasyas how are you setting up the state with launcUrls? I'd like to insert an auth token on AsyncStorage so I could run tests independently from the atuh spec

@moQuez that's exactly what I was doing with launchUrls.

In my app I had a block in my bootstrap code that checks whether app was launched with launchUrl (and listens to the launchUrls changes as per RN doc). If launch url contained auth token - I initialized app state with it.

Was this page helpful?
0 / 5 - 0 ratings