【问题标题】:authorize camera test in integration testing在集成测试中授权相机测试
【发布时间】:2021-08-14 15:40:49
【问题描述】:

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

【问题讨论】:

    标签: flutter integration-testing


    【解决方案1】:

    有了新的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();
    }
    

    【讨论】:

    • 知道为什么我在尝试这种方法时会收到ProcessException: Permission denied 吗?
    • 你在用windows吗?如果不是,你只需要在 linux/mac 中使用 adb 而不是 adb.exe
    • 不,macOS ...我已经放弃了,哈哈
    • 我认为您当前在 shell/cmd 中运行用户时遇到了一些问题。也许你会在那里找到答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    相关资源
    最近更新 更多