问题描述
最近我开始使用XCTest测试iOS应用程序,但发现了一些困难,主要困难是删除或重置每个测试类中的应用程序内容.
Recently I started testing an iOS app using XCTest but I found some difficulties, the main difficulty was deleting or resetting the app content in each test class.
我目前正在使用XCode 11,并尝试针对每个测试类从iOS 13中删除/重置应用程序,我已经尝试过:
I'm currently using XCode 11 and trying to delete/reset an app from iOS 13 for each test class, I've already tried:
- 通过跳板删除应用
- 通过转到应用程序设置删除应用程序
这一步在我的测试中非常重要,因为在每个测试中我都需要创建一个配置文件并登录,因此在下一个测试中,我需要从头开始安装该应用程序
This step is really important in my tests because in each test I need to create a profile and log in, so in the next test I need to have the app just installed from scratch
推荐答案
尝试按一下应用程序图标的时间比以前的iOS版本要长一些.
Try to press the app icon a little longer than in previous iOS versions.
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
func deleteMyApp() {
XCUIApplication().terminate()
let icon = springboard.icons["YourAppName"]
if icon.exists {
let iconFrame = icon.frame
let springboardFrame = springboard.frame
icon.press(forDuration: 5)
// Tap the little "X" button at approximately where it is. The X is not exposed directly
springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + 3) / springboardFrame.maxX, dy: (iconFrame.minY + 3) / springboardFrame.maxY)).tap()
springboard.alerts.buttons["Delete"].tap()
}
}
这篇关于如何使用XCTest从iOS 13中删除/重置应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!