Allow permission dialog in Flutter end-to-end testing?

In Flutter end-to-end testing, a permission is to be allowed during the test. driver.tap(find.text("ALLOW") does not work. How to click "ALLOW".

enter image description here


Solution 1:

You can grant the permissions before running the test.

import 'dart:io';
import 'package:path/path.dart';

// ...

setUpAll(() async {
  final envVars = Platform.environment;
  final adbPath = join(
    envVars['ANDROID_SDK_ROOT'] ?? envVars['ANDROID_HOME'],
    'platform-tools',
    Platform.isWindows ? 'adb.exe' : 'adb',
  );
  await Process.run(adbPath, [
    'shell',
    'pm',
    'grant',
    'com.example.yourapp', // replace with your app id
    'android.permission.RECORD_AUDIO'
  ]);
  driver = await FlutterDriver.connect();
});

Solution 2:

for me above code is not working don't know why

then i'm tried with below code and its working

setUpAll(() async {

      await Process.run('add_adb_path/adb.exe' , ['shell' ,'pm', 'grant', 'add_app_package_name', 'android.permission.ACCESS_MEDIA_LOCATION']);
      await Process.run('add_adb_path/adb.exe' , ['shell' ,'pm', 'grant', 'add_app_package_name', 'android.permission.READ_EXTERNAL_STORAGE']);
      await Process.run('add_adb_path/adb.exe' , ['shell' ,'pm', 'grant', 'add_app_package_name', 'android.permission.WRITE_EXTERNAL_STORAGE']);


      driver = await FlutterDriver.connect();
    });