How do I Quickly Automate Sending FCM or APNS Messages?

百般思念 提交于 2021-01-27 04:42:30

问题


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?


回答1:


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.



回答2:


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.




回答3:


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/



来源:https://stackoverflow.com/questions/53057192/how-do-i-quickly-automate-sending-fcm-or-apns-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!