iOS - Logout from Apple Store / Restore Device Programmatically

一曲冷凌霜 提交于 2019-12-25 08:36:45

问题


I'm automating test cases to run in several devices in parallel. I'm using Appium for this and this works fine. My issue is that I have some test cases that need the device to be logged into specific Apple Store accounts. Also, it is possible that the device might already be logged into another account and I don't have the option to logout manually. My test cases to log into an account if the device has no account attached to it already run well (inside my app I try to do an action that requires an Apple ID, the alert requiring login appears and I already automated the login process). The issue is when the device is already logged into another account.

My two options are:

  • Force the device to log out from Apple Store
  • Create a device backup without being logged and restore this backup before my test

I wasn't able to find a way to handle the first option. The second one works using idevicebackup2 (a lib from libimobiledevice). The issue here is that after restoring the device data, the setup wizard appear and there is no way to get rid of it automatically. I tried using cfgutils to remove the wizard steps, but even after removing all steps, the wizard appears just waiting for a confirmation after restoring.

I would like to know if there is a way to go for the first option, or a way to skip the setup wizard in the second option, or maybe a way to restore the backup partially (just clearing the Apple ID data) in order to avoid rebooting the device and getting stuck with the wizard again. Thanks in advance.


回答1:


One option available now with Xcode 9 is the new multi-app testing. You can now call any app on the system based on it's bundle identifier XCUIApplication(bundleIdentifier: "com.MEGACORP.xyz") during a XCUI test. They cover the new API and examples in WWDC session 409 - What's New in Testing - it's worth watching the whole thing.

I've written some tests using the new API to switch out of the app under test and open System Settings to reset the app state during the test teardown. There's a list of all the system bundle ids in this question.

Your test would start with something like:

let store = XCUIApplication(bundleIdentifier: "com.apple.AppStore")
store.launch()


来源:https://stackoverflow.com/questions/43687581/ios-logout-from-apple-store-restore-device-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!