Flutter测试出现错误:ProcessException: 权限被拒绝。

3

我正在尝试在我的设备上运行端到端测试,因此我必须通过adb请求访问位置权限。当我从终端运行命令时,它按预期工作,但当dart:io执行时,它会抛出此异常(对于每个adb命令都是相同的)。

环境:

  • MacOS
  • Android Studio

代码:

void main() {
  group('Testing full app flow', () {
    IntegrationTestWidgetsFlutterBinding.ensureInitialized();

    setUpAll(() async {
      await Process.run('adb' , ['shell' ,'pm', 'grant', 'com.MYSERVICE', 'android.permission.ACCESS_FINE_LOCATION']); 
    });

    testWidgets('test the password input on real device/emulator', (tester) async {

     //TESTS

    });

  });
}
2个回答

2
我找到了正确的方法: 现在,由于测试正在设备上运行(显然无法adb自身),因此adb命令需要在驱动程序中。 应该像这样:
import 'dart:io';

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() async {
  await Process.run('adb' , ['shell' ,'pm', 'grant', 'com.myapp','android.permission.ACCESS_FINE_LOCATION']);
  await Process.run('adb' , ['shell' ,'pm', 'grant', 'com.myapp','android.permission.ACCESS_COARSE_LOCATION']);
  await integrationDriver();
}

如此描述:https://github.com/flutter/flutter/issues/12561

目前我还没有在 iOS 上完成,但会稍后更新。

附注:运行命令仍为:

flutter drive
--driver=integration_test/driver.dart
--target=integration_test/app_test.dart
-d DEVICE

但 Flutter_blue 仍然认为蓝牙已停用。


0

请使用超级用户尝试:

sudo flutter run

它不起作用是因为这不是(所有者)权限的问题,问题在于集成测试的结构发生了变化,当diver_test变成integration_test时,就像我在答案中解释的那样。 - lou habert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接