I am having an issue in experimenting with flutter integration tests. My goal is to be able to run headless tests for training purposes (a student produces an app, that I will test automatically). As it runs on servers it has to be headless and as quick as possible, so I chose chromedriver (I am not sure this is the best choice though, if you have other ideas please feel free to tell me).
I followed the tutorial here: https://flutter.dev/docs/cookbook/testing/integration/introduction
I created an empty project, filled lib/main.dart, test_driver/app.dart, test_driver/app_test.dart and pubspec.yaml exactly as suggested on the link above.
Then I tried to run this command:
flutter drive --target=test_driver/app.dart
Everything works properly, all tests passed
Then I launched chromedriver with chromedriver --port=4444 and tried to launch the test on chrome as suggested in the tutorial:
flutter drive test_driver/app.dart --browser-name=chrome --release
In this situation, after some time chrome opens and immediately crash ("Application finished"), juste before app_test.dart is launched:
Running "flutter pub get" in test_simple... 657ms
Launching test_driver/app.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome... 17,1s
This app is linked to the debug service: ws://127.0.0.1:33437/_FLIixzh_w0=/ws
Debug service listening on ws://127.0.0.1:33437/_FLIixzh_w0=/ws
Running with sound null safety
Application finished.
00:00 +0: Counter App (setUpAll)
Then the tests hang here forever until I kill it manually. Adding the "-v" flag does not give more information on why the application itself has finished:
[ +23 ms] Running "flutter pub get" in test_simple... (completed in 828ms)
[ +172 ms] Generating /home/bolgar/StudioProjects/test_simple/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
[ +90 ms] Launching test_driver/app.dart on Chrome in debug mode...
[ +125 ms] Updating assets
[ +99 ms] Waiting for connection from debug service on Chrome...
[ +102 ms] <- reset
[ +5 ms] /home/bolgar/snap/flutter/common/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /home/bolgar/snap/flutter/common/flutter/bin/cache/artifacts/engine/linux-x64/frontend_server.dart.snapshot
--sdk-root /home/bolgar/snap/flutter/common/flutter/bin/cache/flutter_web_sdk/ --incremental --target=dartdevc --debugger-module-names --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true
--output-dill /tmp/flutter_tools.KSIJUI/flutter_tool.EKPQRL/app.dill --libraries-spec file:///home/bolgar/snap/flutter/common/flutter/bin/cache/flutter_web_sdk/libraries.json --packages
/home/bolgar/StudioProjects/test_simple/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-root
/home/bolgar/StudioProjects/test_simple/test_driver --filesystem-root /home/bolgar/StudioProjects/test_simple/test --filesystem-root /tmp/flutter_tools.KSIJUI/flutter_tools.XZNNYT --filesystem-scheme
org-dartlang-app --initialize-from-dill build/b1b715402d823b7fd5c2b68d2edcb2ce.cache.dill.track.dill --platform
file:///home/bolgar/snap/flutter/common/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk_sound.dill --sound-null-safety
[ +8 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+15724 ms] Waiting for connection from debug service on Chrome... (completed in 15,8s)
[ ] Synced 30.4MB.
[ ] <- accept
[ ] Caching compiled dill
[ +73 ms] Using Google Chrome 93.0.4577.63
[ +491 ms] [CHROME]:
[ ] [CHROME]:DevTools listening on ws://127.0.0.1:45213/devtools/browser/359be11c-4ac2-4ec0-b7ff-4fb67b69bf85
[ +169 ms] DwdsInjector: Received request for entrypoint at http://localhost:36257/main_module.bootstrap.js
[ +4 ms] MetadataProvider: Loading debug metadata...
[ +11 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[ +5 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:36257/main_module.bootstrap.js
[+1576 ms] ChromeProxyService: Initializing expression compiler for main_module.bootstrap.js with sound null safety: true
[ +47 ms] DevHandler: Debug service listening on ws://127.0.0.1:39027/zQL0xCzGkSU=/ws
[ +15 ms] This app is linked to the debug service: ws://127.0.0.1:39027/zQL0xCzGkSU=/ws
[ +4 ms] Debug service listening on ws://127.0.0.1:39027/zQL0xCzGkSU=/ws
[ ] Running with sound null safety
[ +522 ms] Application finished.
[ +27 ms] DevHandler: Stopped debug service on ws://127.0.0.1:38021
[ +355 ms] executing: /home/bolgar/snap/flutter/common/flutter/bin/cache/dart-sdk/bin/dart /home/bolgar/StudioProjects/test_simple/test_driver/app_test.dart -rexpanded
[+1584 ms] 00:00 +0: Counter App (setUpAll)
[ +180 ms] DwdsInjector: Received request for entrypoint at http://localhost:36257/main_module.bootstrap.js
[ ] MetadataProvider: Loading debug metadata...
[ +6 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[ +2 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:36257/main_module.bootstrap.js
[+104632 ms] DwdsInjector: Received request for entrypoint at http://localhost:36257/main_module.bootstrap.js
[ ] MetadataProvider: Loading debug metadata...
[ +6 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[ +2 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:36257/main_module.bootstrap.js
Can anyone help me here on how to debug this situation ? I must admit that I am stuck.
Thanks a lot,
PS: I would also like to output the results of the drive test in JSON format, as you do with flutter test --machine ..., but I can't find a way to do it with flutter drive ..., so if anyone has a clue please tell me, otherwise I will open another post.