我正在尝试编写一些从登录尝试开始的集成测试,然后继续将应用程序导航到某个页面。登录尝试实际上成功了,但在那之后我尝试查找任何小部件失败了,所以我无法进一步导航。
登录页面后,应用程序会自动正确导航到应用程序中的下一页,但是我的测试脚本在该页面上找不到任何小部件,即使我可以在屏幕上的 android 模拟器中看到它们。
我的 app_test.dat 文件如下所示:
import ...
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('sign in : ', () {
testWidgets('try to SIGN IN and open the menu ',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle(const Duration(milliseconds: 5000));
await tester.pumpAndSettle();
expect(find.text('SIGN IN', skipOffstage: false), findsWidgets);
expect(find.byKey(Key('loginPagePasswordField')), findsOneWidget);
expect(find.byKey(Key('loginPageEmailField')), findsOneWidget);
print('found fields');
await tester.enterText(
find.byKey(Key('loginPageEmailField')), 'myname@here.com');
await tester.enterText(
find.byKey(Key('loginPagePasswordField')), 'myname123zxc');
print('entered text');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();
print('entered DONE');
await tester.pumpAndSettle(const Duration(milliseconds: 5000));
await tester.pumpAndSettle();
// Now try to find the menu icon button
var x = find.byTooltip('Open navigation menu');
expect(x, findsOneWidget); // this fails but is needed to navigate the app
print('find tab1 ');
// Now try to find the 'ASD' Tab
final tabFinder = find.text('ASD', skipOffstage: false);
expect(tabFinder, findsWidgets); // this also fails
});
});
}
和我的 f 医生(我使用 fvm):
[✓] Flutter (Channel stable, 2.8.0, on macOS 12.1 21C52 darwin-arm, locale en-CA)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.0)
[✓] Connected device (2 available)
• No issues found!