This tip is not new. I implemented this maybe around five years ago.
In general, push notification related feature is difficult to automate since it requires external service. We must send a request to push notification server and should wait for the notification.
If we focused on Android Application, we could make this kind of test automate by adb commands. Android OS launches activities via an intent by broadcast when it gets a message via push notification. BroadcastReceiver is the class Android app should register to get the intent by Android system via push notification system.
It is necessary to ensure by manual from sending a request to the push notification server and the app (kindly the device running the app on) actually can get it. But we can emulate the sending intent part. It is below command.
$ adb shell am broadcast -a com.your.app.intent.YOUR_ACTION --es json_example '{"example": "hello world"}'
You can provide intent arguments following https://developer.android.com/studio/command-line/adb#IntentSpec
With this, you can launch an expected activity via broadcast receiver. You can easy to run the command on CI without exact push notifications.
I found many issues via this automatically when I worked in a company. Engineers focused on their own part. We had various entry-points of push notifications. Such automation prevented critical issues which happened after getting push notifications (and launch the app with tapping the notification!)
1 Comment