这是我第一次在 Flutter 中使用集成测试。
我写了下面的测试代码:
testWidgets('Navigate to password page', (tester) async {
// ! Launch the app.
app.main();
await tester.pumpAndSettle();
await Future.delayed(const Duration(seconds: 2));
// ! Tap on the enter user login page
await tester.tap(find.byKey(const Key('enter_login_page_btn')));
await tester.pumpAndSettle();
// Check if the new page is displayed correctly
expect(find.byKey(const Key('page_user_login')), findsWidgets);
// Enter text into the login/email input field.
await tester.enterText(
find.byKey(const Key('user_input_login')), "[email protected]");
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();
await Future.delayed(const Duration(seconds: 2));
// ! Tap on the validate user login button.
await tester.tap(find.byKey(const Key('validate_login_btn')));
await tester.pumpAndSettle();
await Future.delayed(const Duration(seconds: 2));
}
这是按下“登录”按钮时的代码:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PasswordPage(
email ?? '',
key: const Key('page_user_password'),
),
maintainState: true,
),
);
在正常的手动测试中,导航工作正常,但是当我尝试使用集成测试对其进行测试时,没有任何反应,它不会导航到下一页,即密码页面,并且测试结束。
有人知道为什么导航在集成测试中不起作用吗?