【发布时间】:2021-06-14 18:37:12
【问题描述】:
我正在尝试编写一个 UI 测试,在设备锁定后点击发送的本地通知。到目前为止,我已经成功地点击了在跳板上发送的通知(当设备已经解锁时),但不是来自锁定屏幕。有谁知道这是否可能?
请注意,这与 from questions such as this one 不同,它只是点击主页按钮离开测试中的应用并等待通知。
这是我的测试代码的相关部分:
// ...already did stuff to schedule a local notification...
// now lock screen
XCUIDevice.shared.perform(NSSelectorFromString("pressLockButton"))
// set up query for notification then wait
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let notificationQuery : XCUIElementQuery = springboard
.otherElements["Notification"]
.descendants(matching: .any)
let notification = notificationQuery["MYAPP, now, My Notification Header, Notification message body."]
// fails
XCTAssertTrue(notification.waitForExistence(timeout: 60))
如果我将调用替换为
XCUIDevice.shared.perform(NSSelectorFromString("pressLockButton"))
与
XCUIDevice.shared.press(.home)
然后测试通过。
感谢所有建议!
【问题讨论】:
标签: swift uilocalnotification xcuitest