This project provides a reference implementation of UNTextInputNotificationAction
and XCTestCase
with XCUIApplication
to ensure that notification actions using text responses are propagated correctly through an application.
This project was inspired by joern's reference blog post and stackoverflow answer that used NWPusher and a device to test notifications in Xcode 9. In the five Xcode versions later the iOS simulator has added support for more notifications. Additionally I wanted a reference without relying on NWPusher and setting up external push infrastructure. This approach should be compatible with any existing UI test infrastructure that uses true remote notifications.
- Build and run the project with Xcode 14
- Run the tests in NotificationActionTestUITests.testTextResponse to validate text response actions.
NotificationRegisterModel.registerCategory()
registers aUNTextInputNotificationAction
and allows you to act on notifications.NotificationResponseModel
implementsuserNotificationCenter(, willPresent:, withCompletionHandler:)
to show notifications while the app is in the foreground for testing convenience.userNotificationCenter(, didReceive:, withCompletionHandler:)
forwards the response toViewController.display(response:)
for a complete flow.
ViewController.schedulePush()
starts the lifecycle by sending a local notification that can be acted on.
- Capture a reference to the springboard process
XCUIApplication(bundleIdentifier: "com.apple.springboard")
- Accept push permissions with
addUIInterruptionMonitor
- Query for springboard's element
"NotificationShortLookView"
to act on the notification banner. - Query for springboard's only
textView
element to act on the action response text input.- Note: This is not a text field. Multiple lines are supported input!
- Lastly the text entered through the springboard UI hierarchy is compared against the app's UI hierarchy to ensure completeness.
The base localization is en_US.