mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.92k stars 281 forks source link

`clearState` command doesn't reliably clear UserDefaults on iOS #1601

Open AtomicGeorge opened 1 year ago

AtomicGeorge commented 1 year ago

Describe the bug Launching an app with clearState or calling clearState directly doesn't reliably clear UserDefaults in an iOS app.

To Reproduce

  1. Write a value to UserDefaults in an iOS app.
  2. Quit the app
  3. Launch an app with maestro using
    - launchApp:
    appId: "com.example.app"
    clearState: true

    or -clearState followed by -launchApp

  4. Observe that UserDefaults still contains the previously written value. Expected behavior userDefaults should be cleared and the app should be launched as though it had not been used previously

Environment information (please complete the following information):

Workspace (if applicable) MaestroUserDefaultsTestApp.zip

Additional context A workaround I've found is using -clearState before running launchApp with the clearState option set to true as far as I can tell this should delete everything twice which seems to ensure that the app is fairly reliably launched with a completely clear state.

brandenbyers commented 6 months ago

I'm seeing this same issue. The above workaround does not work for my use case. clearKeychain nor clearState clear the state like they do on Android. The only workaround that I have found is to use xcrun to uninstall and reinstall the app.

Losiowaty commented 2 months ago

@brandenbyers @AtomicGeorge Folks, do you by chance use shared user defaults (in an app group)?

What I've found is that running the idb command found in clearState docs (here) does clean the "regular" UserDefaults just fine, but doesn't touch the shared ones.

AtomicGeorge commented 2 months ago

@brandenbyers @AtomicGeorge Folks, do you by chance use shared user defaults (in an app group)?

What I've found is that running the idb command found in clearState docs (here) does clean the "regular" UserDefaults just fine, but doesn't touch the shared ones.

@Losiowaty The example project just uses standard user defaults, no sharing or anything fancy at all.