Flutter Driver hangs at splash screen

Issue

I am trying to setup Flutter Driver tests for my application and the app runs async so I found https://github.com/flutter/flutter/issues/41029 which says all you need to do is add await driver.waitUntilFirstFrameRasterized(); and it should work, while this does stop the test from failing it nos simply does not run.

The app just hangs at the splash screen never even getting into the application itself.

As far as I am understanding, this is all I would need to have setup in order for the test to run

  FlutterDriver driver;
  // Connect to the Flutter driver before running any tests.
  setUpAll(() async {
    driver = await FlutterDriver.connect();
    await driver.waitUntilFirstFrameRasterized();

    // await Directory('screenshots').create();
  });

  // Close the connection to the driver after the tests have completed.
  tearDownAll(() async {
    if (driver != null) {
      await driver.close();
    }
  });

However, all I am getting in my terminal is the following output:

VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:54264/tt9kN4jBSrc=/
VMServiceFlutterDriver: Isolate found with number: 2942164624858163
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
VMServiceFlutterDriver: Connected to Flutter application.
VMServiceFlutterDriver: waitForCondition message is taking a long time to complete...

I have left it for minutes and nothing happens, I have disabled the firebase initialization in case somehow that is blocking it as I would need to accept the alert dialogue, not that I am even getting that far as I can see.

Solution

Turns out I needed to use an IsolatesWorkaround as well

  FlutterDriver driver;
  IsolatesWorkaround workaround;
  // Connect to the Flutter driver before running any tests.
  setUpAll(() async {
    driver = await FlutterDriver.connect();
    workaround = IsolatesWorkaround(driver);
    await workaround.resumeIsolates();
    await driver.waitUntilFirstFrameRasterized();

    if (!await Directory('screenshots').exists()) {
      await Directory('screenshots').create();
    }
  });

  // Close the connection to the driver after the tests have completed.
  tearDownAll(() async {
    await driver?.close();
    await workaround.tearDown();
  });

See: https://gist.github.com/vishna/03c5d5e8eb14c5e567256782cddce8b4

Answered By – RemeJuan

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *