在Flutter中打开集成测试中的深层链接

问题描述 投票:0回答:2

我正在尝试运行集成测试,该测试高度依赖于用户单击他在电子邮件中收到的神奇链接。到目前为止我还没有找到一种方法来做到这一点。我遇到了

Process.run
,但似乎它应该在集成测试开始之前运行,并且我需要在测试期间执行它。

任何有关 iOS 或 Android 的帮助将不胜感激。 🙏

这是我迄今为止尝试在 iOS 上运行的代码,但

Process.run
ProcessException: No such file or directory
结尾:

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  testWidgets('login test', (WidgetTester tester) async {
    app_sandbox.main();
    await tester.pumpAndSettle(Duration(seconds: 5));
    expect(find.text('foo'), findsOneWidget);
    await Process.run('xcrun', [
      'simctl',
      'openurl',
      '7D6DEC47-C1E2-4F18-A38B-7B4C17558172',
      'https://myDeepLink/sign-in',
    ]);
    await tester.pumpAndSettle();
  });
}
flutter dart testing automated-tests
2个回答
0
投票

这可能仅适用于 flutter_driver

     await Process.run('xcrun', [
        'simctl',
        'openurl',
        'booted',
        'https://myDeepLink/sign-in'
      ]).then((result) {
        stdout.write(result.stdout);
        stderr.write(result.stderr);
      });

不适用于integration_test的testWidgets

我得到了这个错误:

> Error occured: DriverError: Failed to fulfill RequestData due to
> remote error Original error: ext.flutter.driver: (112) Service has
> disappeared Original stack trace:
> #0      new _OutstandingRequest (package:vm_service/src/vm_service.dart:1746:45)
> #1      VmService._call (package:vm_service/src/vm_service.dart:2262:21)
> #2      VmService.callServiceExtension (package:vm_service/src/vm_service.dart:2233:14)
> #3      VMServiceFlutterDriver.sendCommand (package:flutter_driver/src/driver/vmservice_driver.dart:306:66)
> #4      FlutterDriver.requestData (package:flutter_driver/src/driver/driver.dart:522:45)
> #5      integrationDriver (package:integration_test/integration_test_driver_extended.dart:51:38)
> <asynchronous suspension>

0
投票

这是一个老问题,但我想把它留在这里给其他需要它的人。您可以在集成测试中通过

WidgetsFlutterBinding
发送到平台的链接,并且您正在使用的任何路由系统都应该拾取该链接,然后进行适当的处理。

这是我为集成测试制作的帮助程序,可在测试期间随时发送链接

Future<void> sendDeepLink(WidgetTester tester, String link) async {
  final binding = WidgetsFlutterBinding.ensureInitialized();
  binding.handlePushRoute(link);
  await tester.pumpAndSettle();
}
© www.soinside.com 2019 - 2024. All rights reserved.