I am trying the solution for e2e test for image_picker from this link How to test ImagePicker in Flutter Driver?
void main() {
enableFlutterDriverExtension();
const MethodChannel channel =
MethodChannel('plugins.flutter.io/image_picker');
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
ByteData data = await rootBundle.load('images/sample.png');
Uint8List bytes = data.buffer.asUint8List();
Directory tempDir = await getTemporaryDirectory();
File file = await File(
'${tempDir.path}/tmp.tmp',
).writeAsBytes(bytes);
print(file.path);
return file.path;
});
});
app.main();
}
My main file for test is exactly the same. The issue is that when I am using enableFlutterDriverExtension();
the test right after start, finished with the info that all test passed, without emulating steps on emulator and print all the info to console after every step. And in the console I am getting
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter_driver/src/extension/extension.dart': Failed assertion: line 222 pos 10:
'WidgetsBinding.instance == null': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 enableFlutterDriverExtension (package:flutter_driver/src/extension/extension.dart:222:10)
#3 main
Without enableFlutterDriverExtension(); test fail when I am trying to call image_picker. With error
flutter: 'package:flutter_test/src/binding.dart': Failed assertion: line 775 pos 14: '_pendingExceptionDetails != null': A test overrode FlutterError.onError
but either failed to return it to its original state, or had unexpected additional errors that it could not handle. Typically, this is caused by using expect()
before restoring FlutterError.onError.
flutter: dart:core-patch/errors_patch.dart 47:61 _AssertionError._doThrowNew
What exactly the enableFlutterDriverExtension(); do? Without testing image_picker and this enableFlutterDriverExtension() tests are working correctly. Is there any other solution for testing image_picker?