Flutter Driver hangs at splash screen

只愿长相守 提交于 2021-02-11 12:26:35

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/64797858/flutter-driver-hangs-at-splash-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!