FlutterDriver: Flutter Driver extension is taking a long time to become available

4,456

I've followed the steps on the docs for writing integration tests and it works fine on both Flutter stable(version 1.22.5) and master(version 1.26.0-2.0.pre.281) channels. While the command in the docs demonstrates the use of flutter drive, using flutter driver seems to run fine as well in my tests.

Setting that aside, even if I'm unable to replicate the issue locally, it seems that the issue has been resolved by following the workaround mentioned in the GitHub issue thread per checking the comments.

Share:
4,456
Sergi R
Author by

Sergi R

Updated on December 11, 2022

Comments

  • Sergi R
    Sergi R over 1 year

    I'm trying to run flutter integration tests following the instructions provided in the webpage: https://flutter.dev/docs/cookbook/testing/integration/introduction but when trying to execute using an iOS device, it always fails with a flutterdriver timeout, but if I'm executing the same piece of code using an android device it runs successfully.

    The command executed is:

    flutter driver --target=test_driver/app.dart
    

    and (only in iOS), the error shown is the following:

    ...
    flutter: Observatory listening on http://127.0.0.1:49605/Jh_J7boSKBk=/  
    Installing and launching...                                        22.5s
    [info ] FlutterDriver: Connecting to Flutter application at http://127.0.0.1:1043/Jh_J7boSKBk=/
    [trace] FlutterDriver: Isolate found with number: 589047572
    [trace] FlutterDriver: Isolate is paused at start.
    [trace] FlutterDriver: Attempting to resume isolate
    [trace] FlutterDriver: Waiting for service extension
    flutter: main dev
    [warning] FlutterDriver: Flutter Driver extension is taking a long time to become available. Ensure your test app (often "lib/main.dart") imports "package:flutter_driver/driver_extension.dart" and calls enableFlutterDriverExtension() as the first call in main().
    

    it looks like that when it is executed in iOS, it is completely ignoring the specified target and it is trying to run directly lib/main.dart file but, WHY?

    What I mean for following webpage instructions is using 2 files for test: test_driver/app.dart and test_driver/app_test.dart

    test_driver/app.dart

    import 'package:flutter_driver/driver_extension.dart';
    import 'package:my_app/main.dart' as app;
    
    void main() async {
      // This line enables the extension
      await enableFlutterDriverExtension();
    
      // Call the `main()` function of your app or call `runApp` with any widget you
      // are interested in testing.
      await app.main();
    }
    

    test_driver/app_test.dart

    import 'package:flutter_driver/flutter_driver.dart';
    import 'package:test/test.dart';
    
    void main() {
      group('end-to-end test', () {
        FlutterDriver driver;
    
        setUpAll(() async {
          // Connect to a running Flutter application instance.
          driver = await FlutterDriver.connect();
        });
    
        tearDownAll(() async {
          if (driver != null)
            driver.close();
        });
    
        test('whatever', () async {
           //whatever
        });
      });
    }
    

    As it was commented here: #17184, it could be fixed introducing the enableFlutterDriverExtension() inside main.dart, but I would rather not write anything extra inside the application code.

    Is there any possibility to fix it using another approach?

    Thanks