I want to UI test my app with push notifications and maybe some of you have found a best practice. There are a lot tutorials and questions but I wasn’t able to find a satisfying answer.
- Start test
- Send push notifcation
- Tap push notifcation
- Do stuff
But what would be the best practice to send the push notification?
- Rest Call that triggers the push notification
- Get access to the terminal (but how?) and run:
xcrun simctl push <device> com.example.my-app ExamplePush.apns
- Send local push notifications?
- Mock Server
- use a Framework like Mussel
Thanks! 🙂
2
Answers
For testing purpose if you want to create testing push notification then
https://github.com/noodlewerk/NWPusher
This library is very helpful.
Use terminal to test push notification with single line command
Install Houston in your Mac, run below command in terminal.
gem install houston
If you are facing error like this,
Fetching houston-2.4.0.gem
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
First run below commands in terminal to install Ruby
brew install ruby
export GEM_HOME="$HOME/.gem"
gem install rails
after successful installation run again
gem install houston
Go to the pem files folder and open terminal from that folder.
Run below command like
apn push "Device Token" -c PEM_FILE_NAME -m "MESSAGE"
Like:
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_dev.pem -m "Testing"
after successful run of above command it will ask for PEM pass phrase which is password of your pem file.
If your app is lived then use production pem file name
like this,
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_pro.pem -m "Testing"
Done.
For UI Testing you can use Local notification,
You have to set categoryIdentifier for local notification also make sure that same categoryIdentifier set into UNNotificationExtensionCategory in your AppExtension Info.plist file
For more in detail kindly refer below link
https://levelup.gitconnected.com/custom-push-notification-in-ios-swift-5-210552643e86#:~:text=Go%20to%20xcode%20select%20File,have%20its%20unique%20category%20Identifier.
Below is the sample code to fire local notification with Category Identifier