I am attempting to write a a UI test that taps on a delivered local notification after the device has been locked. I have been successful so far in tapping on a notification that was delivered on the springboard (when the device is already unlocked) but not from the lock screen. Does anyone know if this is possible?
Please note that this is different from questions such as this one, which merely hit the home button to leave the app under test and wait for the notification.
Here is the relevant portion of my test code:
// ...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))
If I replace the call to
XCUIDevice.shared.perform(NSSelectorFromString("pressLockButton"))
with
XCUIDevice.shared.press(.home)
then the test passes.
All suggestions appreciated!