【发布时间】:2019-12-12 14:55:10
【问题描述】:
我指的是在运行每个 XCUItest 后删除应用程序的下面的 github 代码。 https://gist.github.com/KoCMoHaBTa/5d2cecfc17db5f3944bc98bcd6fcde55
但是代码 sn-p let icon = springboard.icons["myAppName"] 无法识别我的应用。我已将 myAppName 替换为我的应用程序名称以及检查 icon.exists 是否始终返回 false 的 if 条件。跳板类如下所示。我这里有什么遗漏吗?
class Springboard {
static let shared = Springboard()
let springboard = XCUIApplication(bundleIdentifier: "com.company.me")
func deleteApp(withName name: String) {
XCUIApplication().terminate()
let springboard = self.springboard
//springboard.resolve()
springboard.activate()
let icon = springboard.icons[name]
sleep(5)
//let icon = springboard.icons.matching(identifier: "ONE").firstMatch
//let icon = springboard.otherElements["Home screen icons"].scrollViews.otherElements.icons["ONE"]
if icon.exists {
let iconFrame = icon.frame
let springboardFrame = springboard.frame
//Tap & Hold the app icon in order to go to edit mode
Thread.sleep(forTimeInterval: 0.5)
icon.press(forDuration: 1.3)
//Tap the little "X" button at approximately where it is. The X is not exposed directly
Thread.sleep(forTimeInterval: 0.5)
springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + 5) / springboardFrame.maxX, dy: (iconFrame.minY + 5) / springboardFrame.maxY)).tap()
//tap the delete alert button
Thread.sleep(forTimeInterval: 0.5)
springboard.alerts.buttons["Delete"].tap()
}
//Press home once make the icons stop wiggling
Thread.sleep(forTimeInterval: 0.5)
XCUIDevice.shared.press(.home)
}
}
【问题讨论】:
-
执行这段代码时,在Springboard页面上是否可以看到app图标?
-
不确定我是否理解正确。您是说在执行上述代码时,模拟器上是否可以看到应用程序图标?如果是,那么是的,它是可见的。否则我不明白你所说的跳板页面是什么意思。
标签: ios ui-automation xcuitest