I am testing an app using firebase push notifications using appium.
Now I want to send a test notification to the app. For this I need the fcm token from the app.
The app is a production build, it does not display or expose the fcm token anywhere, why should it?
But of course I need to access the token from my appium tests. Is there a good way to extract data normally not exposed using adb? Or some other mechanism on how to get the fcm token without displaying it on a label in the app?
Appium itself is actually using adb to get data related to the app.
If you cannot get fcm token via adb (for security reasons its shouldn't be possible), there is no way Appium can get it.
You may look into Firebase API to check if you can get token from service side. Still the best option will be to use test build where you modified app to expose token.
Related
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?
First of all, I would think about what scenario do we want to cover.
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.
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
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.
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.
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/
I'm trying to create a python app that pretends to be an android mobile app.
The app I'm trying to mimic is using firebase cloud messaging client. and it's using the FirebaseMessaging.getInstance().getInstanceId() method to get a token.
Google documentation mentions:
On initial startup of your app, the FCM SDK generates a registration
token for the client app instance. If you want to target single
devices or create device groups, you'll need to access this token by
extending FirebaseMessagingService and overriding onNewToken.
All the communications between the server is encrypted with this token. and in order to communicate the to app server I need to be able to generate this token.
My question is how can I generate a new token? is there a particular endpoint for this?
I've seen this and this but none of them mention how its getting done.
I have a web app made by laravel framework and I want to send notifications from my web app to the android and ios versions of my platform, I'm considering using firebase for notifications.
But here is the problem the authentication (registration) is not done using firebase It's done using the web application because users are not allowed to make their own accounts(it must be given to them), now I find my self in a dilemma because if the authentication is not done using firebase I can't get the fcm token, and therefor I can't send notifications.
My question is there a way to get a device's fcm token without having it authenticating using firebase?
And if that is not possible is there any other way to send notifications in the manner i described?
I think you are mixing two different things.
1) The user registration with the web site (This happens in you web site/application and has nothing to do with FCM).
2) The registration of the device to FCM done through the google account set on the Android Device.
The way this works is that the device register's to FCM, at that point your app receives a "callback" (onTokenRefresh()) from FCM informing you about the new token that was created for the device.
In that callback you call the web site's server and associate the FCM token you received with the account of the user that registered to the website (1). The association would be kept in a table in a database so you can lookup the token by the user id assigned by the web application.
I am working on an app and the Android version implements Firebase for Instance ID, Cloud Messaging and Analytics. Everything is working properly in regards to obtaining the instance id and FCM token.
I also built a server API for sending notifications and data payloads to Android devices and in order to use the same methods in the iOS version I decided to use Firebase for iOS for the same purposes (Instance ID, Cloud Messaging and Analytics).
Setting up Firebase on iOS is well documented and I was able to set the environment for everything to work properly. However, when I run the app I got the following error in the console (which means that the instance id and FCM token were not retrieved):
....
[Firebase/InstanceID][I-IID003009] Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
[Firebase/InstanceID][I-IID003007] Failed to retrieve the default GCM token after 5 retries
Wait, I know there are other people complaining about the same issue here but this is a totally different case.
I thought that my setup was incorrect or missing something but I reviewed all the procedures and code and everything was 100% correct.
Where I am located (Damascus, Syria), some services are blocked by Google and can only be accessible via a proxy or a VPN. Therefore I setup a US proxy for both the device I am using for testing and the simulator and when I run the app everything works properly and I was able to get the instance id and the FCM token and log them in the console.
What is weird is that in the Firebase Console the analytics is showing the correct number of users even when the FCM token was not received which means that the communication with the Firebase service is not totally blocked. The only part which is not working (without a proxy) is fetching the FCM token.
My question is: Why this particular Firebase service is blocked in iOS and not in Android and can I do anything about it? Remember that I have no problem in getting the token in Android from the same location. Or is this a bug in Firebase and the service is not location bound?
I have no problem in connecting to Google APIs from my location for other purposes like Google Maps or getting information about an FCM token..etc. However, I noticed that the console is referring to iid.firebase.com instead of iid.googleapis.com.
Any help or suggestion in this regard will be appreciated because I want to make a decision whether I should keep trying to use Firebase in both platforms or if I should rely on Firebase for Android and the native APNs ways for iOS. Also, I want to know if my decision to implement Firebase was the correct one in the first place.
Thanks!
I just switched my app over to firebase 2.0 from parse. Basically I have an android app (main app) built for the general public to use. Then I also built a second app (manager app) that only I and a few others have access to which is used to update the content of the main app. Now I am adding in notifications which work fine when I send them from the firebase console, however, is it possible to send them from the manager app to the main app? If not, what would I need to do in order to send them from somewhere other than the console (I don't want anyone else to have access to the console but would like them to be able to send notifications.) Thanks!
Seems like you are looking for device to device messaging. This is not currently supported by FCM, so you will need some type of server.
The server could implement XMPP in which case it can be a relay, upstream messages from admin client will be converted to downstream messages to non-admin clients.
The server could watch the Firebase Relatime Database and then the admin client could write something to the database and the server watching the database could then take action and send notifications to non-admin clients.