What you Need to know About Automating Push Notification Testing

What you Need to know About Automating Push Notification Testing

Push notifications are used to integrate real-time messaging to your apps. It keeps you in touch with users and makes it easy for your users to communicate. These are easy to love and hate.

However, testing push notifications for your iOS or Android app can be a pain.

Consider setting up your own server or use one of the many push web services online. Either way, it’s a lot of work to get all these systems connected properly. When it is working properly, push notifications come in fast and reliably, (Awesome). But, when nothing comes in, it can be very hard to find out why.

You can test push notification feature in 3 different application modes:

  • Foreground Mode – Test push notification when app is running

  • Background Mode – Test push notification when app is in background

  • Suspend Mode – Test push notification when app is not running

You can always test push notification manually in all three mode by sending push notifications from your server or by using online push notification test services and checking the device for notification message received. Doing this means the user/tester has to manually check the devices for notification message received in all 3 modes.

How we can automate Push Notification Testing?

We can automate the process of testing push notification by writing test scripts that verify whether the push notification message was received or not. We need to have the app in the foreground to verify the UI. Unfortunately, it’s not feasible to run automation test script when the application is in the background or in suspend mode. But, you can test it in the background using network assert.

There are 2 ways to verify the Push Notification was received on any device

1. UI Assertion for a banner when the App is in the foreground

For this you write a test case that does the following:

  • Make an API call that sends the Access Point Name (APN) or Google Cloud Messaging (GCM) message to your test device

  • Launch the Application and keep it running in the foreground

  • Pass the test case if the banner or notification appears on the screen in the specified time duration, otherwise it fails the test case

2. Network Level Assertion for the APNs or GCM

We can write test case that does the following:

  • Makes an API call that sends APN or GCM message to test device

  • Launch the Application and keep it running in the foreground

  • Verify that push.apple.com (iOS) or gcm-http.googleapis.com(android) network request is made or not to pass or fail the test

Push notifications are a great tool for communicating with your users. Testing them can be a pain but we’ve figured out a few clever ways to automate it and save you time.

This blog is originally published at TestGrid