Description
Since the Flutter 2.5 upgrade, tester.enterText()
seems broken in my web integration tests in --release mode.
When I run flutter drive
with --no-headless
, I can see that no text is added in text fields.
Steps to Reproduce
You can reproduce it with this repo https://github.com/rxlabz/text_drive
sh drive_web.sh
sh drive_web_release.sh
You can also see the result of 3 GH actions workflows in the project :
-
the first is running the integration_test without
--release
(https://github.com/rxlabz/text_drive/blob/master/.github/workflows/integration.yaml) => it works ( all tests passed ) https://github.com/rxlabz/text_drive/actions/runs/1217290271 -
the other uses--release (https://github.com/rxlabz/text_drive/blob/master/.github/workflows/integration_release.yaml) and fails => https://github.com/rxlabz/text_drive/actions/runs/1217290268
-
the last one is running with flutter 2.2.3 in --release https://github.com/rxlabz/text_drive/actions/runs/1217434660/workflow => it works https://github.com/rxlabz/text_drive/runs/3556551737
App
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => const MaterialApp(home: MainScreen());
}
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
final TextEditingController controller = TextEditingController();
String value = 'test';
@override
void initState() {
super.initState();
controller.addListener(() => setState(() => value = controller.text));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(key: const Key('field'), controller: controller),
Text(value)
],
),
),
);
}
}
integration test
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:text_drive/main.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets("failing test example", (WidgetTester tester) async {
await tester.pumpWidget(const App());
final input = find.byKey(const Key('field'));
expect(input, findsOneWidget);
expect(find.text('test'), findsOneWidget);
await tester.tap(input);
await tester.enterText(input, 'Hello');
// same result with `updateEditingValue`
// (cf.https://flutter.dev/docs/release/breaking-changes/enterText-trailing-caret)
// await tester.showKeyboard(input);
// await tester.pumpAndSettle();
//tester.testTextInput.updateEditingValue(
// const TextEditingValue(text: 'Hello'),
//);
await tester.pump();
expect(find.text('Hello'), findsNWidgets(2));
});
}