简体   繁体   English

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

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

I'm during migration to work with new Xcode 12, but I have a problem with UI tests.我正在迁移以使用新的 Xcode 12,但我在 UI 测试方面遇到了问题。 Code代码

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

not working anymore and I can't find how to indicate notification view.不再工作,我找不到如何指示通知视图。 How was it changed?怎么改的?

It seems like notification elements have a slightly different accessibility hierarchy in iOS 14. This should work:似乎通知元素在 iOS 14 中的可访问性层次结构略有不同。这应该有效:

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

It's interesting to observe that the actual XCUIElement that represents the push notification has type "BannerNotification" (an XCUIElementType with a rawValue representation 83) which I couldn't find in the public headers.有趣的是,表示推送通知的实际XCUIElement类型为“BannerNotification”(一个XCUIElementType ,rawValue 表示为 83),我在公共标题中找不到它。 Might be a private type at the moment.目前可能是私有类型。 Hence the workaround with decendants(matching: .any) .因此, decendants(matching: .any)的解决方法。

Also accessing/asserting inside the notification is possible:还可以在通知内访问/断言:

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