我正在尝试为我的应用程序设置Flutter Driver测试,并且该应用程序异步运行,所以我发现https://github.com/flutter/flutter/issues/41029
表示您需要做的就是添加await driver.waitUntilFirstFrameRasterized();
并且它应该可以工作,但是这确实会停止失败失败的测试根本无法运行。
该应用程序只是挂在初始屏幕上,甚至从未进入应用程序本身。
据我所知,这是我运行测试所需的全部设置
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();
}
});
但是,我在终端中得到的只是以下输出:
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...
我已经离开它几分钟了,什么也没发生,我已经禁用了Firebase初始化,以防万一某种原因阻止了它,因为我需要接受警报对话框,而不是我能看到的那么远。 / p>
答案 0 :(得分:0)
原来我也需要使用IsolatesWorkaround
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();
});
请参阅:https://gist.github.com/vishna/03c5d5e8eb14c5e567256782cddce8b4