Opening deep link in integration test in Flutter
Asked Answered
H

2

7

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();
  });
}
Him answered 16/3, 2022 at 9:41 Comment(0)
C
0

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>
Copycat answered 6/9, 2022 at 18:35 Comment(0)
C
0

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();
}
Chrystal answered 12/9 at 20:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.