最近,我开始使用XCTest测试iOS应用,但发现了一些困难,主要困难是删除或重置每个测试类中的应用内容。
我目前正在使用XCode 11,并尝试针对每个测试类从iOS 13删除/重置应用,我已经尝试过:
此步骤在我的测试中非常重要,因为在每个测试中我都需要创建一个配置文件并登录,因此在下一个测试中,我需要从头开始安装该应用程序
[尝试按一下应用程序图标的时间比以前的iOS版本要长一些。
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()
}
}