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".

- 12,447
- 10
- 56
- 83
4 Answers
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();
});

- 3,073
- 1
- 22
- 18
-
13how to grant permission for iOS? – Saeed Jassani Nov 14 '20 at 01:52
-
3Hey this is giving me `ProcessException: No such file or directory` error when executing – Bhupesh Varshney Jan 27 '22 at 12:29
-
1@BhupeshVarshney I am getting the same problem ``ProcessException: No such file or directory`` when executing – Humayun Kabir Mar 25 '22 at 11:13
-
@SaeedJassani `xcrun simctl privacy ... grant ...` – ch271828n May 25 '22 at 03:55
-
1IOS : await Process.run('xcrun', [ 'simctl', 'privacy', 'booted', 'grant', 'all', 'your.package.name']); – zap Aug 11 '22 at 10:23
-
ProcessException: Operation not permitted Command: xcrun simctl privacy booted grant all – vontdeux Dec 01 '22 at 09:16
-
@vontdeux did you fix granting permissions for ios? – Kristi Jorgji Jan 30 '23 at 11:08
-
no i gave up on the idea of doing it on physical ios :S – vontdeux Apr 02 '23 at 14:53
Other answers will not help you if you are using the latest Flutter Integration Testing as there we don't require FlutterDriver to connect.
So now, you need to add the below code in test_driver.dart file where we initialize integrationDriver()
Future<void> main() async {
final Map<String, String> envVars = Platform.environment;
String? 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', 'android.permission.CAMERA']);
await Process.run(adbPath , ['shell' ,'pm', 'grant', 'com.example', 'android.permission.WRITE_EXTERNAL_STORAGE']);
await integrationDriver();
}
This change is required as FlutterDriver
makes the connection once you initialized and connect it, but the new flow of integration testing already had a connection, so we need to initialize it before the connection happens.
To run code, use the below command on terminal, as you see for better result I have created two folder,
test_driver: Contains the driver code mentioned above.
integration_test: Contains test files.
flutter drive --driver=test_driver/test_driver.dart --target=integration_test/my_test.dart

- 31,138
- 12
- 157
- 147
-
Where do I find that `test_driver.dart` file? I don't have one in my project... – Emil S. Jan 22 '22 at 13:06
-
1
-
Thanks, I've figured out by now I have to create it. Kinda sucks that I can no longer use Android Studio for running the tests though. – Emil S. Jan 24 '22 at 16:40
-
What about ios ? How can we grant location permission to ios ? @EmilS. you can still use android studio for running these tests by creating a custom dart command and specifying the driver flag there to match your drive file as well – Kristi Jorgji Jan 30 '23 at 10:01
-
Try Patrol – it makes cases like yours easy to handle!
- First, set up Patrol in your app
- Install patrol_cli –
dart pub global activate patrol_cli
Once you get the initial setup done, you'll able to write in your tests:
await $.native.grantPermissionWhenInUse();
To run this test, simply type patrol test
.
In contrast to the other answers from Susovan, apaatsio and Jitesha, Patrol works on iOS and Android.
Full code example
// integration_test/recording_test.dart
import 'package:patrol/patrol.dart';
void main() {
patrolTest( // patrolTest() instead of testWidgets()
'records sounds and saves it to internal storage',
nativeAutomation: true,
(PatrolTester $) async { // PatrolTester instead of WidgetTester
await $.pumpWidget(YourAppWidget()); // replace with your own
await $('Record').tap(); // Patrol's custom finders syntax (optional)
await $.native.grantPermissionWhenInUse();
},
);
}
To run it:
patrol test
More about Patrol
Patrol is available on pub.dev and has extensive documentation. Here's a succinct overview of the native features it supports.
Apart from interacting with native features, Patrol has:
- custom widget finders, which make tests much shorter and more robust
patrol develop
command, which supports Hot Restart in integration tests, speeding up development cycles- Support for Firebase Test Lab & more!

- 1,085
- 3
- 15
- 37
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();
});

- 35
- 6