在Flutter端到端测试中允许权限对话框?

时间:2018-12-05 21:51:27

标签: testing flutter end-to-end

在Flutter端到端测试中,在测试期间必须允许权限。 driver.tap(find.text("ALLOW")不起作用。如何单击“允许”。

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以在运行测试之前授予权限。

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();
});

答案 1 :(得分:1)

对我来说上面的代码不起作用不知道为什么

然后我尝试使用以下代码及其工作

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();
    });