I have setup integration tests for firebase using guide. I am running the same tests at local using following command:
flutter build apk --debug --flavor dev
./gradlew app:assembleDevDebugAndroidTest
./gradlew app:connectedDevDebugAndroidTest -Ptarget=integration_test/main_test.dart
I'm able to run tests successfully but the apk asks for permissions if it's new device or reinstalled the app.
I added following code to flutter_app/android/app/src/androidTest/java/com/domain/myapp/MainActivityTest.java to implement GrantPermissionRule as mentioned still it didn't work.
@RunWith(FlutterTestRunner.class)
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, true, false);
@Rule
public GrantPermissionRule mRuntimePermissionRule =
GrantPermissionRule.grant(android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.READ_PHONE_STATE,
android.Manifest.permission.READ_MEDIA_VIDEO,
android.Manifest.permission.READ_MEDIA_IMAGES,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.CAMERA,
android.Manifest.permission.ACCESS_FINE_LOCATION
);
}
Is there a way to grant permissions in Flutter Instrumentation tests?
In driver folder test_driver/integration_test: Below example is to accept permission for location and similarly you can add other permissions also using adb for android