我正在为我们公司的应用程序编写测试。
我正在测试的登录界面有2个简单的文本字段,和一个按钮。由于输入了错误的凭据,测试失败。然后显示ErrorDialog(自定义小部件)。ErrorDialog显示一个简单的错误消息,并有一个“完成”按钮。当我尝试通过单击“完成”关闭小部件时,没有任何React。测试似乎找不到小部件。但是当我按下完成按钮时,Flutter确实会为我的点击动作提供建议。但所有建议的解决方案都不起作用。有人知道我做错了什么吗?
import 'package:**/app/main.dart' as app;
import 'package:common/presentation/generic/widgets/buttons/borderless_button.dart';
import 'package:common/presentation/generic/widgets/buttons/**_blue_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('login page end-to-end tests', () {
testWidgets(
'STEP 1: Tap on login from splashscreen and fill in the login credentials. \n'
'STEP 2: Tap on the login button in order to attempt authentication with an invalid email adress. \n'
'STEP 3: Press done button when invalid email is entered. \n'
'STEP 4: Enter valid credentials. '
'STEP 5: Tap on login button in order to authenticate with valid password and email \n',
(tester) async {
app.main();
await tester.pumpAndSettle();
final loginButton = find.byType(BorderlessButton).first;
await tester.tap(loginButton);
await tester.pumpAndSettle();
final userNameField = find.byType(TextFormField).first;
final passwordField = find.byType(TextFormField).last;
final submitButton = find.byType(CoinmerceBlueButton).first;
await tester.enterText(userNameField, 'x');
await tester.enterText(passwordField, 'x');
await tester.pumpAndSettle();
await tester.tap(submitButton);
await tester.pumpAndSettle();
final doneButton = find.byKey(const ValueKey("errorDialog"));
await tester.tap(doneButton);
await tester.pumpAndSettle();
expect(
find.text('Dit lijkt geen geldig e-mailadres te zijn.'),
findsOneWidget,
);
});
});
}
我的小部件树:
先谢谢你了!
1条答案
按热度按时间kcrjzv8t1#
我遇到了完全相同的问题,它是从使用等待时,显示对话框。本质上,“pumpAndSettle”等待所有Futures返回,直到按下“Close”按钮,对话框才结束。因此,测试在按下关闭按钮之前等待对话框关闭。