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

发布于 2025-01-15 00:27:44 字数 152 浏览 1 评论 0原文

我正在尝试运行一个集成测试,该测试高度依赖于用户单击他在电子邮件中收到的魔术链接。到目前为止我还没有找到一种方法来做到这一点。我遇到了 Process.run,但它似乎应该在集成测试开始之前运行,并且我需要在测试期间执行它。

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

I'm trying to run an integration test which is highly dependent on the user clicking a magic link he got in his email. So far I failed to find a way of doing that. I came across Process.run but it seems like it should be run before the integration test starts and I need to do it during the test.

Any help with either iOS or Android will be highly appreciated. ????

This is the code I tried so far to work on iOS but Process.run ends with 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();
  });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆离笙 2025-01-22 00:27:44

这可能只适用于 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>

this might only work with flutter_driver

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

not with testWidgets of integration_test

there I got this error:

> 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>
Smile简单爱 2025-01-22 00:27:44

这是一个老问题,但我想把它留在这里供其他需要它的人使用。您可以在集成测试中通过 WidgetsFlutterBinding 发送到平台的链接,并且您正在使用的任何路由系统都应该拾取该链接,然后进行适当的处​​理。

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

Future<void> sendDeepLink(WidgetTester tester, String link) async {
  final binding = WidgetsFlutterBinding.ensureInitialized();
  binding.handlePushRoute(link);
  await tester.pumpAndSettle();
}

This is an old issue, but I wanted to leave this here for anyone else that needs it. You can send a link to the platform through the WidgetsFlutterBinding in an integration test, and it should be picked up by whatever routing system you are using then handled appropriately.

This is the helper I made for integration tests to send a link at any point during a test

Future<void> sendDeepLink(WidgetTester tester, String link) async {
  final binding = WidgetsFlutterBinding.ensureInitialized();
  binding.handlePushRoute(link);
  await tester.pumpAndSettle();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文