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

问题描述

我正在迁移中,以使用新的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)的解决方法。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...