I am trying to setup flutter driver on my project. I already did work with it in another project and didn't had these problems. I initialised flutter_driver in the dev_dependencies, and put an app.dart and app_test.dart under test_driver folder. I initalized app.dart to have a running app with flutter driver and started to write my first tests. Strangely I am getting super weird errors, when i try to interact with certain widgets. A simple driver.waitFor or driver.tap gives me a timeout.
This is my code:
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
void main() {
group('App', () {
late FlutterDriver driver;
// Connect to the Flutter driver
setUpAll(() async {
// Connect to a running Flutter application instance.
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
await driver.close();
});
test('should check driver health status', () async {
final health = await driver.checkHealth();
expect(health.status, HealthStatus.ok);
});
Future waitForObject(
SerializableFinder object,
Duration timeout, {
String errorMessage = "waitForObject timed out",
}) async {
final message = "ERROR ==> $errorMessage";
return driver.waitFor(object, timeout: timeout).catchError((e) {
throw message;
});
}
test(
'should tap on getting started button',
() async {
final gettingStartedButton = find.byValueKey('GETTING_STARTED');
// Give the app some time to load
await Future.delayed(const Duration(seconds: 1));
print(
await waitForObject(
gettingStartedButton,
const Duration(seconds: 5),
),
);
// final widgetTree = await driver.getRenderTree();
// print(widgetTree.tree);
// await driver.runUnsynchronized(() async {
// await driver.waitFor(gettingStartedButton);
// });
await driver.waitFor(gettingStartedButton);
await driver.tap(gettingStartedButton);
},
timeout: Timeout.none,
);
});
}
flutter drive --target=test_driver/app.dart
error messages i logged:
- ERROR ==> waitForObject timed out
- VMServiceFlutterDriver: waitFor message is taking a long time to complete
The app is starting and i also logged the widget tree and the elements are in the visible spot. Health status of flutter driver is ok as well. I also tried driver.runUnsynchronized, but nothing seems to work.
I also tried to set Timeout.none, but that didn't help: flutter-driver timeout
Any ideas?