How do I Quickly Automate Sending FCM or APNS Messages?
Asked Answered
J

3

7

I am developing a backend service that sends push notifications to mobile apps via either FCM or APNS. I would like to create an automated test that can run in under a minute and validates that the server can successfully send a notification. Note that I do not necessarily need to check that the notification has been delivered, just that FCM or APNS has successfully processed the request to send the message.

I know that theoretically I could automate this test using a tool like appium and use test hooks to retrieve a registration/device token from the app, but it seems cumbersome to use appium to test if the backend can send a message. I have also tried to use a hard coded registration token, but registration and device tokens are prone to rotate, so the test could suddenly stop passing. Are there any other options?

Jeane answered 30/10, 2018 at 3:57 Comment(0)
P
4

First of all, I would think about what scenario do we want to cover.

  1. Maybe, we want to check that we sent a request to FCM when it is needed. This case might be done on a unit level with mocked classes responsible for sending a push.
  2. If you want to test specifically success of the FCM call, then you don't actually need a correct Firebase token of the user device. According to docs, if everything is configured correctly and you send a message to a user using incorrect token (or even without it), you will still get http code 200. As a result, you may use usual integration test that will call Firebase API and check the success code (200) and error field (MissingRegistration / InvalidRegistration / NotRegistered), and if you get such a pair - your request was succesfull. There is no much need to test it with a correct user device token, because if everything else is correct, the result will be the same (but actually delivered to a phone). Firebase docs
  3. In case if you still want to use an actual token, you can create a special build type for you QAs, that will send their Firebase token to a special endpoint on your server on each app start. As a result, you will always have a recent Firebase token stored on your server to use for test purposes. Of course, that test may still be flacky but it is a good starting point.
Poster answered 8/11, 2018 at 18:43 Comment(0)
A
1

Appium is automation framework for black-box testing, so in your case, it allows to check if the notification pops up on a device. And that's it.

Appium has no access to your application code, you can send adb commands via it, but basically, no way to play with tokens until you expose it to the UI layer of your app.

Moreover, Appium is not supported by Firebase.

I suggest looking into Espresso, where you write tests with direct access to your application code.

Atelectasis answered 30/10, 2018 at 18:46 Comment(2)
I'm actually trying to test the back end, not the app itself. The goal is to test that the back end can send a notification without the mobile app.Jeane
That's the deal: appium allows only e2e UI testing, no way to test app back-endAtelectasis
W
0

You can write cloud functions to achieve this in firebase which can be pushed using firebase CLI from local system.This cloud functions can be written in Nodejs.
You can go this documentation for writing cloud functions.
https://firebase.google.com/docs/functions/

These cloud functions can be triggered on some events like change in real time database,when user signup etc. and you can get tokens from mobile app using callbacks on registered listeners and we can use them to push notifications to app. You can go through following simple project.
https://aaronczichon.de/2017/03/13/firebase-cloud-functions/

Wardmote answered 9/11, 2018 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.