iosreact-nativedetox

Enable notification while test with Detox isn't working


I'm trying to enable the permissions by using device.launchApp({ permissions: { notifications: 'YES' } }), however it seems not being called.

This is my test:

describe('Mobile test', () => {
  beforeAll(async () => {
    await detox.init(config, { launchApp: false });
    await device.launchApp({ permissions: { notifications: 'YES' } });
  });

  describe('Smoke', () => {
    it('my test', async () => {
      mock.cardData.assignee = mock.signupData.profile.fullName;
      await Operator.signup(mock.signupData);
    });
  });
});

This is the output of the test using verbose loglevel:

detox[8345] INFO:  [DetoxServer.js] server listening on localhost:65156...
detox[8345] DEBUG: [AsyncWebSocket.js/WEBSOCKET_OPEN] opened web socket to: ws://localhost:65156
detox[8345] DEBUG: [DetoxServer.js/LOGIN] role=tester, sessionId=087d9cea-5251-fbda-160a-f89d4927dee3
detox[8345] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=tester, sessionId=087d9cea-5251-fbda-160a-f89d4927dee3
detox[8345] DEBUG: [exec.js/EXEC_CMD, #0] /usr/bin/xcrun simctl list -j
detox[8345] DEBUG: [exec.js/EXEC_CMD, #1] applesimutils --list --byType "iPhone X" --byOS "12.2"
detox[8345] DEBUG: [exec.js/EXEC_TRY, #1] Searching for device matching iPhone X...
detox[8345] DEBUG: [exec.js/EXEC_CMD, #2] applesimutils --list --byId "B2E486B7-8CD7-4B94-9969-3C6901591BD8"
detox[8345] DEBUG: [exec.js/EXEC_CMD, #3] /usr/bin/xcrun simctl uninstall B2E486B7-8CD7-4B94-9969-3C6901591BD8 com.amadeu.mobileapp
detox[8345] DEBUG: [exec.js/EXEC_TRY, #3] Uninstalling com.amadeu.mobileapp...
detox[8345] DEBUG: [exec.js/EXEC_SUCCESS, #3] com.amadeu.mobileapp uninstalled
detox[8345] DEBUG: [exec.js/EXEC_CMD, #4] /usr/bin/xcrun simctl install B2E486B7-8CD7-4B94-9969-3C6901591BD8 "/Users/amadeu.filho/Developer/amadeu-mobile/ios/build/Build/Products/Debug-iphonesimulator/amadeumobile.app"
detox[8345] DEBUG: [exec.js/EXEC_TRY, #4] Installing /Users/amadeu.filho/Developer/amadeu-mobile/ios/build/Build/Products/Debug-iphonesimulator/amadeumobile.app...
detox[8345] DEBUG: [exec.js/EXEC_SUCCESS, #4] /Users/amadeu.filho/Developer/amadeu-mobile/ios/build/Build/Products/Debug-iphonesimulator/amadeumobile.app installed
detox[8345] DEBUG: [exec.js/EXEC_CMD, #5] /usr/bin/xcrun simctl terminate B2E486B7-8CD7-4B94-9969-3C6901591BD8 com.amadeu.mobileapp
detox[8345] DEBUG: [exec.js/EXEC_TRY, #5] Terminating com.amadeu.mobileapp...
detox[8345] DEBUG: [exec.js/EXEC_SUCCESS, #5] com.amadeu.mobileapp terminated
detox[8345] DEBUG: [exec.js/EXEC_CMD, #6] SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/Users/amadeu.filho/Library/Detox/ios/1ea4f89e9092026849f937e47281627c5f5251d6/Detox.framework/Detox" /usr/bin/xcrun simctl launch B2E486B7-8CD7-4B94-9969-3C6901591BD8 com.amadeu.mobileapp --args -detoxServer "ws://localhost:65156" -detoxSessionId "087d9cea-5251-fbda-160a-f89d4927dee3"
detox[8345] DEBUG: [exec.js/EXEC_TRY, #6] Launching com.amadeu.mobileapp...
detox[8345] DEBUG: [exec.js/EXEC_CMD, #7] /usr/bin/xcrun simctl get_app_container B2E486B7-8CD7-4B94-9969-3C6901591BD8 com.amadeu.mobileapp
detox[8345] INFO:  [AppleSimUtils.js] com.amadeu.mobileapp launched. To watch simulator logs, run:
        /usr/bin/xcrun simctl spawn B2E486B7-8CD7-4B94-9969-3C6901591BD8 log stream --level debug --style compact --predicate 'processImagePath beginsWith "/Users/amadeu.filho/Library/Developer/CoreSimulator/Devices/B2E486B7-8CD7-4B94-9969-3C6901591BD8/data/Containers/Bundle/Application/6F69DC89-7478-4502-8998-8B93E8D061C6/amadeumobile.app"'
detox[8345] DEBUG: [DetoxServer.js/CANNOT_FORWARD] role=testee not connected, cannot fw action (sessionId=087d9cea-5251-fbda-160a-f89d4927dee3)
detox[8345] DEBUG: [DetoxServer.js/LOGIN] role=testee, sessionId=087d9cea-5251-fbda-160a-f89d4927dee3
detox[8345] DEBUG: [DetoxServer.js/LOGIN_SUCCESS] role=testee, sessionId=087d9cea-5251-fbda-160a-f89d4927dee3

I also tried to call applesimutils manually while the app is opened, however, I don't know whether the detox uses a different bundle to run the test suite or not.

āžœ applesimutils --byId "B2E486B7-8CD7-4B94-9969-3C6901591BD8" --bundle com.amadeu.mobileapp --setPermissions notifications=YES

I'm using an iPhone X simulator.

      "buildversion" : "16E226",
      "availability" : "(available)",
      "isAvailable" : true,
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-12-2",
      "version" : "12.2",
      "name" : "iOS 12.2"

Solution

  • It seems that we should init detox without launch and then use device.launchApp({ permissions: { notifications: 'YES' } })

    So, in the init.js file, you can use:

    const detox = require('detox');
    const adapter = require('detox/runners/jest/adapter');
    const specReporter = require('detox/runners/jest/specReporter');
    const config = require('../package.json').detox;
    
    jest.setTimeout(120000);
    jasmine.getEnv().addReporter(adapter);
    jasmine.getEnv().addReporter(specReporter);
    
    beforeAll(async () => {
      await detox.init(config, { launchApp: false });
      await device.launchApp({ permissions: { notifications: 'YES' } });
    });
    
    beforeEach(async () => {
      await adapter.beforeEach();
    });
    
    afterAll(async () => {
      await adapter.afterAll();
      await detox.cleanup();
    });