授权集成测试中的摄像头测试



我正在为Flutter应用程序编写集成测试。该应用程序允许用户拍摄视频。在编写测试时,当权限对话框出现时,如何在集成测试脚本内允许应用程序的相机权限?

使用新的integration_test包,您可以在test_driver/integration_test.dart:内授予android中的权限

// this permission grant workaround works only for android for now
Future<void> main() async {
final Map<String, String> envVars = Platform.environment;
final String adbPath =
envVars['ANDROID_SDK_ROOT']! + '/platform-tools/adb.exe';
await Process.run(adbPath, [
'shell',
'pm',
'grant',
'com.app.name',
'android.permission.CAMERA'
]);
await Process.run(adbPath, [
'shell',
'pm',
'grant',
'com.app.name',
'android.permission.RECORD_AUDIO'
]);
await integrationDriver();
}

最新更新