-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
In previous integration tests for my Flutter apps, a crucial method was FlutterDriver.waitFor as it allowed the app to load up something before performing the actual test case.
With the migration to the integration_test package, this is not possible anymore. We cannot access FlutterDriver.waitFor anymore and there is no analog in the WidgetTester class.
The doc actually states:
Instead of calling
driver.wait*API, useWidgetTester.pumpAndSettle()or equivalent methods.
However, this is not actually feasible.
Why there are no equivalent methods
Let us use the example of a loading screen for an app.
WidgetTester.pumpAndSettle()will not work at all if there is a static screen that will be replaced after some loading as it only waits for no frames being scheduled but simply cannot wait for any loading.WidgetTester.pumpAndSettle(const Duration(seconds: 2))as an example also does not work because loading will differ based on network speed, device speed, etc.
Proposal
The FlutterDriver.wait* methods should be introduced to WidgetTester. Thinking about it, the same methods should also be useful for regular widget tests anyway.
Furthermore, it is a regression to not have these. I can in fact not even migrate my old flutter_driver tests to integration_test.
Workaround
One workaround I found was writing my own waitFor function:
Future<void> waitFor(WidgetTester tester, Finder finder) async {
do {
await tester.pumpAndSettle();
await Future.delayed(const Duration(milliseconds: 100));
} while (finder.evaluate().isEmpty);
}