0
  • I am curently trying to implement a test for push notifications but I am facing some troubles with the handling system.

My e2e test looks like this:

```
it('Init from push notification', async () => {
    await device.launchApp({newInstance: true, userNotification: userNotificationPushTrigger});
    await expect(element(by.text('From push'))).toBeVisible();
  });

const userNotificationPushTrigger = {
  "trigger": {
    "type": "push"
  },
  "title": "From push",
  "subtitle": "Subtitle",
  "body": "Body",
  "badge": 1,
  "payload": {
    "key1": "value1",
    "key2": "value2"
  },
  "category": "com.example.category",
  "content-available": 0,
  "action-identifier": "default"
};
```
Prutii35
  • 41
  • 1
  • 4

2 Answers2

2

You need to connect the native part of your application to send notifications to RN. On the iOS example, we don't handle notifications in RN at all. You can see this here: https://github.com/wix/Detox/blob/c8f4b28599358e465fb326810453a28bb4509a22/detox/test/ios/example/AppDelegate.m#L203

You can implement a similar method, but instead route the notification to RN. You can also use open source frameworks that do this for you, such as react-native-notification.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
1

I think the detox documentation could do with some clarity around what information is required in the various fields - e.g. category and action-identifier

I'm trying to test an app which works with real notifications. The system notification is being triggered but it doesn't link to the RN app. The RN app does have didReceiveRemoteNotification (and local) handlers but I don't think I'm setting up the notification correctly, hence it is never reaching the app.

EDIT: I've persevered and whilst I'm definitely no expert I have bumbled through and wanted to share my finding in case they help. FYI - I'm using react-native-firebase 5.6.0 to handle the notifications, and testing on RN 0.62.2 with an iPhone 11 simulator on iOS 13.5 I was getting hung up on getting the right system attributes in the notification (category, action) as I thought that was necessary for ios to deliver the notification to my app. I think Detox takes care of that though in some kind of hard wiring as whatever I set these values to the messages are still delivered to the notification handlers registered with RN firebase. My problem was simpler than that in that my payload was wrong and I did not notice the errors in my log. I still think Detox would benefit from better documentation but this is working very well for me in handling a foreground notification

Nick Jones
  • 131
  • 1
  • 7
  • 3
    This is a comment, not an answer. `didReceiveRemoteNotification:` is legacy API, that is no longer supported by Detox. This is mentioned in the documentation: https://github.com/wix/Detox/blob/master/docs/Guide.Migration.md#1400 Detox documentation is not meant to teach how to write apps, only to help you test them. – Léo Natan Jun 14 '20 at 23:00
  • Hey Nick, would you mind sharing the code that got you to the solution? – user3779502 Sep 22 '20 at 12:57