如果我运行此代码段:
await tester.enterText(
find.byKey(Key('titleControlKey')), 'Sample Account 1');
await tester.enterText(find.byKey(Key('usernameControlKey')), 'username1');
或者这个:
await tester.enterText(
find.byKey(Key('titleControlKey')), 'Sample Account 1');
await tester.enterText(find.byKey(Key('passwordControlKey')), 'password1');
它都有效。
但如果我运行三个:
await tester.enterText(
find.byKey(Key('titleControlKey')), 'Sample Account 1');
await tester.enterText(find.byKey(Key('usernameControlKey')), 'username1');
await tester.enterText(find.byKey(Key('passwordControlKey')), 'password1');
测试将失败并产生此错误:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following StateError was thrown running a test:
Bad state: No element
When the exception was thrown, this was the stack:
#0 Iterable.single (dart:core/iterable.dart:654:25)
#1 WidgetController.state (package:flutter_test/src/controller.dart:156:42)
#2 WidgetTester.showKeyboard.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1042:42)
#3 WidgetTester.showKeyboard.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1041:39)
#6 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#7 WidgetTester.showKeyboard (package:flutter_test/src/widget_tester.dart:1041:27)
#8 WidgetTester.enterText.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1077:13)
#9 WidgetTester.enterText.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1076:39)
#12 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#13 WidgetTester.enterText (package:flutter_test/src/widget_tester.dart:1076:27)
#14 AddAccountScreenRobot.enterAccountDetails (file:///C:/Users/Noyruto/sources/repos/account_saver/integration_test/robots/add_account_screen_robot.dart:25:18)
<asynchronous suspension>
<asynchronous suspension>
(elided 5 frames from dart:async and package:stack_trace)