FlutterDriver:Flutter Driver扩展需要很长时间才能使用



我正试图按照网页中提供的说明运行颤振集成测试:https://flutter.dev/docs/cookbook/testing/integration/introduction但当尝试使用iOS设备执行时,它总是会失败,并导致flatterdriver超时,但如果我使用android设备执行同一段代码,它会成功运行。

执行的命令是:

flutter driver --target=test_driver/app.dart

和(仅在iOS中),显示的错误如下:

...
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().

看起来,当它在iOS中执行时,它完全忽略了指定的目标,并试图直接运行lib/main.art文件,但是,为什么?

我对以下网页说明的意思是使用2个文件进行测试:test_driver/app.dart和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
});
});
}

正如这里评论的那样:#17184,在main.dart中引入enableFlutterDriverExtension()是可以修复的,但我不想在应用程序代码中写任何额外的东西。

有没有可能用另一种方法来解决这个问题?

感谢

我已经按照文档中的步骤编写了集成测试,它在Flutter稳定(版本1.22.5)和master(版本1.26.0-2.0.pre.281)通道上都运行良好。虽然文档中的命令演示了flutter drive的使用,但在我的测试中使用flutter driver似乎也很好。

抛开这一点不谈,即使我无法在本地复制问题,根据GitHub问题线程中提到的解决方法,每次检查评论,问题似乎已经得到了解决。

相关内容

  • 没有找到相关文章

最新更新