繁体   English   中英

如何通过 UI 测试(Xcode 12、iOS14)访问推送通知?

[英]How to get access into push notification with UI tests (Xcode 12, iOS14)?

我正在迁移以使用新的 Xcode 12,但我在 UI 测试方面遇到了问题。 代码

let springBoard = XCUIApplication(bundleIdentifier: appleBundleIdentifier) let notification = springBoard.otherElements["NotificationShortLookView"]

不再工作,我找不到如何指示通知视图。 怎么改的?

似乎通知元素在 iOS 14 中的可访问性层次结构略有不同。这应该有效:

let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let notification = springBoard.otherElements["Notification"].descendants(matching: .any)["NotificationShortLookView"]

有趣的是,表示推送通知的实际XCUIElement类型为“BannerNotification”(一个XCUIElementType ,rawValue 表示为 83),我在公共标题中找不到它。 目前可能是私有类型。 因此, decendants(matching: .any)的解决方法。

还可以在通知内访问/断言:

let notification = springBoard.otherElements["Notification"].descendants(matching: .any)["APPNAME, now, TITLE, BODY"]
    if notification.waitForExistence(timeout: 10) {
        notification.tap()
    }

如果有人要测试通知是否有附件,请在通知正文后添加“附件”

let notification = springBoard.otherElements["Notification"].descendants(matching: .any)["APPNAME, now, TITLE, BODY, Attachment"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM