app_test.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import "package:flutter/material.dart";
  2. import "package:flutter_test/flutter_test.dart";
  3. import "package:integration_test/integration_test.dart";
  4. import "package:photos/main.dart" as app;
  5. import "package:scrollable_positioned_list/scrollable_positioned_list.dart";
  6. void main() {
  7. group("App test", () {
  8. final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  9. binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
  10. testWidgets("Demo test", (tester) async {
  11. app.main();
  12. await tester.pumpAndSettle(const Duration(seconds: 5));
  13. await dismissUpdateAppDialog(tester);
  14. //Automatically clicks the sign in button on the landing page
  15. final signInButton = find.byKey(const ValueKey("signInButton"));
  16. await tester.tap(signInButton);
  17. await tester.pumpAndSettle();
  18. //Need to enter email address manually and clicks the login button automatically
  19. final emailInputField = find.byKey(const ValueKey("emailInputField"));
  20. final logInButton = find.byKey(const ValueKey("logInButton"));
  21. await tester.tap(emailInputField);
  22. await tester.pumpAndSettle(const Duration(seconds: 20));
  23. await findAndTapFAB(tester, logInButton);
  24. //Need to enter OTT manually and clicks the verify button automatically
  25. final ottVerificationInputField =
  26. find.byKey(const ValueKey("ottVerificationInputField"));
  27. final verifyOttButton = find.byKey(const ValueKey("verifyOttButton"));
  28. await tester.tap(ottVerificationInputField);
  29. await tester.pumpAndSettle(const Duration(seconds: 6));
  30. await findAndTapFAB(tester, verifyOttButton);
  31. //Need to enter password manually and clicks the verify button automatically
  32. final passwordInputField =
  33. find.byKey(const ValueKey("passwordInputField"));
  34. final verifyPasswordButton =
  35. find.byKey(const ValueKey("verifyPasswordButton"));
  36. await tester.tap(passwordInputField);
  37. await tester.pumpAndSettle(const Duration(seconds: 10));
  38. await findAndTapFAB(tester, verifyPasswordButton);
  39. await tester.pumpAndSettle(const Duration(seconds: 1));
  40. await dismissUpdateAppDialog(tester);
  41. //Grant permission to access photos. Must manually click the system dialog.
  42. final grantPermissionButton =
  43. find.byKey(const ValueKey("grantPermissionButton"));
  44. await tester.tap(grantPermissionButton);
  45. await tester.pumpAndSettle(const Duration(seconds: 1));
  46. await tester.pumpAndSettle(const Duration(seconds: 3));
  47. //Automatically skips backup
  48. final skipBackupButton = find.byKey(const ValueKey("skipBackupButton"));
  49. await tester.tap(skipBackupButton);
  50. await tester.pumpAndSettle(const Duration(seconds: 2));
  51. await binding.traceAction(
  52. () async {
  53. //scroll gallery
  54. final scrollablePositionedList =
  55. find.byType(ScrollablePositionedList);
  56. await tester.fling(
  57. scrollablePositionedList,
  58. const Offset(0, -5000),
  59. 4500,
  60. );
  61. await tester.pumpAndSettle();
  62. await tester.fling(
  63. scrollablePositionedList,
  64. const Offset(0, 5000),
  65. 4500,
  66. );
  67. await tester.fling(
  68. scrollablePositionedList,
  69. const Offset(0, -7000),
  70. 4500,
  71. );
  72. await tester.pumpAndSettle();
  73. await tester.fling(
  74. scrollablePositionedList,
  75. const Offset(0, 7000),
  76. 4500,
  77. );
  78. await tester.fling(
  79. scrollablePositionedList,
  80. const Offset(0, -9000),
  81. 4500,
  82. );
  83. await tester.pumpAndSettle();
  84. await tester.fling(
  85. scrollablePositionedList,
  86. const Offset(0, 9000),
  87. 4500,
  88. );
  89. await tester.pumpAndSettle();
  90. },
  91. reportKey: 'scrolling_summary',
  92. );
  93. });
  94. });
  95. }
  96. Future<void> findAndTapFAB(WidgetTester tester, Finder finder) async {
  97. final RenderBox box = tester.renderObject(finder);
  98. final Offset desiredOffset = Offset(box.size.width - 10, box.size.height / 2);
  99. // Calculate the global position of the desired offset within the widget.
  100. final Offset globalPosition = box.localToGlobal(desiredOffset);
  101. await tester.tapAt(globalPosition);
  102. await tester.pumpAndSettle(const Duration(seconds: 3));
  103. }
  104. Future<void> dismissUpdateAppDialog(WidgetTester tester) async {
  105. await tester.tapAt(const Offset(0, 0));
  106. await tester.pumpAndSettle();
  107. }