From 17b8b0239f9faafa6811a396be56e5f997d6280f Mon Sep 17 00:00:00 2001 From: alex-minaiev-frontegg Date: Tue, 10 Dec 2024 11:11:34 +0200 Subject: [PATCH] FR-18979: Added Login Via email and password test --- example/integration_test/fixtures/const.dart | 5 + .../login_via_email_and_password_test.dart | 92 +++++++++++++++++++ example/lib/login_page.dart | 1 + example/lib/user_tab.dart | 5 +- 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 example/integration_test/fixtures/const.dart create mode 100644 example/integration_test/src/login_via_email_and_password_test.dart diff --git a/example/integration_test/fixtures/const.dart b/example/integration_test/fixtures/const.dart new file mode 100644 index 0000000..3927683 --- /dev/null +++ b/example/integration_test/fixtures/const.dart @@ -0,0 +1,5 @@ +const loginEmail = 'alexm122322@gmail.com'; +const loginPassword = 'Testing123?'; + +const loginWrongEmail = 'some.wrong.email@gmail.com'; +const loginWrongPassword = 'Testing123?2231'; \ No newline at end of file diff --git a/example/integration_test/src/login_via_email_and_password_test.dart b/example/integration_test/src/login_via_email_and_password_test.dart new file mode 100644 index 0000000..1d552dd --- /dev/null +++ b/example/integration_test/src/login_via_email_and_password_test.dart @@ -0,0 +1,92 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:frontegg_flutter_example/main.dart'; +import 'package:patrol/patrol.dart'; + +import '../fixtures/const.dart'; + +void main() { + patrolTest( + 'Success Login via email and password', + ($) async { + await $.pumpWidget(const MyApp()); + await $.pumpAndSettle(); + + await $.tap(find.byKey(const ValueKey("LoginButton"))); + await Future.delayed(const Duration(seconds: 5)); + + await $.native.enterTextByIndex( + loginEmail, + index: 0, + keyboardBehavior: KeyboardBehavior.alternative, + ); + + await $.native.enterTextByIndex( + loginPassword, + index: 1, + keyboardBehavior: KeyboardBehavior.alternative, + ); + + await $.native.tap(Selector(text: "Sign in")); + + await $.waitUntilVisible(find.text("Logout")); + + await $.tap(find.byKey(const ValueKey("LogoutButton"))); + await $.pumpAndSettle(); + }, + ); + + patrolTest( + 'Failure Login via wrong email and password', + ($) async { + await $.pumpWidget(const MyApp()); + await $.pumpAndSettle(); + + await $.tap(find.byKey(const ValueKey("LoginButton"))); + await Future.delayed(const Duration(seconds: 5)); + + await $.native.enterTextByIndex( + loginWrongEmail, + index: 0, + keyboardBehavior: KeyboardBehavior.alternative, + ); + + await $.native.enterTextByIndex( + loginPassword, + index: 1, + keyboardBehavior: KeyboardBehavior.alternative, + ); + + await $.native.tap(Selector(text: "Sign in")); + + await $.native.waitUntilVisible(Selector(text: "Incorrect email or password")); + }, + ); + + patrolTest( + 'Failure Login via email and wrong password', + ($) async { + await $.pumpWidget(const MyApp()); + await $.pumpAndSettle(); + + await $.tap(find.byKey(const ValueKey("LoginButton"))); + await Future.delayed(const Duration(seconds: 5)); + + await $.native.enterTextByIndex( + loginEmail, + index: 0, + keyboardBehavior: KeyboardBehavior.alternative, + ); + + await $.native.enterTextByIndex( + loginWrongPassword, + index: 1, + keyboardBehavior: KeyboardBehavior.alternative, + ); + + await $.native.tap(Selector(text: "Sign in")); + + await $.native.waitUntilVisible(Selector(text: "Incorrect email or password")); + }, + ); +} diff --git a/example/lib/login_page.dart b/example/lib/login_page.dart index e7fe15f..b163566 100644 --- a/example/lib/login_page.dart +++ b/example/lib/login_page.dart @@ -39,6 +39,7 @@ class LoginPage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( + key: const ValueKey("LoginButton"), child: const Text("Login"), onPressed: () async { await frontegg.login(); diff --git a/example/lib/user_tab.dart b/example/lib/user_tab.dart index 702d17a..cc8916a 100644 --- a/example/lib/user_tab.dart +++ b/example/lib/user_tab.dart @@ -56,9 +56,8 @@ class UserTab extends StatelessWidget { ), if (!state.isLoading) ElevatedButton( - child: const Text( - "Logout", - ), + key: const ValueKey("LogoutButton"), + child: const Text("Logout"), onPressed: () async { await frontegg.logout(); debugPrint("Logout Finished");