问题描述
我正在迁移中,以使用新的Xcode 12,但是UI测试有问题。 代码
let springBoard = XCUIApplication(bundleIdentifier: appleBundleIdentifier) let notification = springBoard.otherElements["NotificationShortLookView"]
不再工作,我找不到如何指示通知视图。怎么改变了?
解决方法
还可以在通知中访问/断言:
let notification = springBoard.otherElements["Notification"].descendants(matching: .any)["APPNAME,now,TITLE,BODY"]
if notification.waitForExistence(timeout: 10) {
notification.tap()
}
,
在iOS 14中,通知元素的可访问性层次结构似乎稍有不同。这应该起作用:
let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let notification = springBoard.otherElements["Notification"].descendants(matching: .any)["NotificationShortLookView"]
有趣的是,表示推送通知的实际XCUIElement
类型为“ BannerNotification”(带有原始值表示形式的XCUIElementType
类型),在公共标头中找不到。目前可能是私有类型。因此,decendants(matching: .any)
的解决方法。