dart Flutter集成测试不与对话框一起工作

dauxcl2d  于 2023-06-19  发布在  Flutter
关注(0)|答案(1)|浏览(147)

我正在为我们公司的应用程序编写测试。
我正在测试的登录界面有2个简单的文本字段,和一个按钮。由于输入了错误的凭据,测试失败。然后显示ErrorDialog(自定义小部件)。ErrorDialog显示一个简单的错误消息,并有一个“完成”按钮。当我尝试通过单击“完成”关闭小部件时,没有任何React。测试似乎找不到小部件。但是当我按下完成按钮时,Flutter确实会为我的点击动作提供建议。但所有建议的解决方案都不起作用。有人知道我做错了什么吗?

  1. import 'package:**/app/main.dart' as app;
  2. import 'package:common/presentation/generic/widgets/buttons/borderless_button.dart';
  3. import 'package:common/presentation/generic/widgets/buttons/**_blue_button.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_test/flutter_test.dart';
  6. import 'package:integration_test/integration_test.dart';
  7. void main() {
  8. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  9. group('login page end-to-end tests', () {
  10. testWidgets(
  11. 'STEP 1: Tap on login from splashscreen and fill in the login credentials. \n'
  12. 'STEP 2: Tap on the login button in order to attempt authentication with an invalid email adress. \n'
  13. 'STEP 3: Press done button when invalid email is entered. \n'
  14. 'STEP 4: Enter valid credentials. '
  15. 'STEP 5: Tap on login button in order to authenticate with valid password and email \n',
  16. (tester) async {
  17. app.main();
  18. await tester.pumpAndSettle();
  19. final loginButton = find.byType(BorderlessButton).first;
  20. await tester.tap(loginButton);
  21. await tester.pumpAndSettle();
  22. final userNameField = find.byType(TextFormField).first;
  23. final passwordField = find.byType(TextFormField).last;
  24. final submitButton = find.byType(CoinmerceBlueButton).first;
  25. await tester.enterText(userNameField, 'x');
  26. await tester.enterText(passwordField, 'x');
  27. await tester.pumpAndSettle();
  28. await tester.tap(submitButton);
  29. await tester.pumpAndSettle();
  30. final doneButton = find.byKey(const ValueKey("errorDialog"));
  31. await tester.tap(doneButton);
  32. await tester.pumpAndSettle();
  33. expect(
  34. find.text('Dit lijkt geen geldig e-mailadres te zijn.'),
  35. findsOneWidget,
  36. );
  37. });
  38. });
  39. }

我的小部件树:

先谢谢你了!

kcrjzv8t

kcrjzv8t1#

我遇到了完全相同的问题,它是从使用等待时,显示对话框。本质上,“pumpAndSettle”等待所有Futures返回,直到按下“Close”按钮,对话框才结束。因此,测试在按下关闭按钮之前等待对话框关闭。

相关问题