Setting camera permissions on Android using Detox

Viewed 716

Description

I'm testing a screen with access to the camera to get a photo. But I can't deal with the permissions dialog in tests on Android.

I run the tests with await device.launchApp({ permissions: { camera: 'YES' }});. This setting worked for iOS. How can I accept all permissions for Android? Or how can I handle the permissions dialog on Android?

To Reproduce

init.js settings

await device.launchApp({
  permissions: { photos: 'YES', camera: 'YES' },
});

emulator settings

{
  "configurations": {
    "android.emu.debug": {
      "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
      "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
      "type": "android.emulator",
      "device": {
        "avdName": "Nexus_S_API_27"
      }
    }
  }
}

Environment

  • Detox: 16.2.1
  • React Native: 0.60.4
  • Node: 12.16.1
  • OS: macOS Mojave 10.14.6
  • Device: emulator Nexus S API 27
1 Answers

I also have this issue on Detox 17.2.0, React Native 0.61, API 27 for my Android emulator. It works perfectly on iOS but on Android, whatever I set NO or YES on permissions, they are always enabled.

If I change theses permissions on the app before launching detox test, all permissions are enabled again.

My tests looks like the following:

describe('Permissions', () => {
  beforeEach(async () => {
    await device.reloadReactNative()
  })

  it('displays no warning when camera and microphone access are authorized', async () => {
    await device.launchApp({ newInstance: true, permissions: { camera: 'YES', microphone: 'YES' } })
    ...
  })

  it('displays a warning message + button to app settings when camera access is denied', async () => {
    await device.launchApp({ newInstance: true, permissions: { camera: 'NO', microphone: 'YES' } })
    ...
  })
})

Detox can not handle this for the moment I guess if you check this issue https://github.com/wix/Detox/issues/2184

Related