Created
November 6, 2024 06:48
-
-
Save kururu-abdo/1fa93a1a32e6d2c8d2163a4f24b772d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:integration_test/integration_test.dart'; | |
import 'package:your_app/main.dart'; // Update with the path to your main app file | |
void main() { | |
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | |
testWidgets('Login flow test', (WidgetTester tester) async { | |
// Pump the app (load the initial screen) | |
await tester.pumpWidget(MyApp()); | |
// Verify that the login screen is displayed | |
expect(find.byType(TextFormField), findsNWidgets(2)); // Expect two TextFormFields (username, password) | |
expect(find.byType(ElevatedButton), findsOneWidget); // Expect one ElevatedButton (submit button) | |
// Enter username and password into the text fields | |
await tester.enterText(find.byType(TextFormField).first, 'testuser'); | |
await tester.enterText(find.byType(TextFormField).at(1), 'password123'); | |
// Tap the submit button | |
await tester.tap(find.byType(ElevatedButton)); | |
// Wait for the navigation to the Home screen | |
await tester.pumpAndSettle(); // pumpAndSettle waits for all animations to finish | |
// Verify that the Home screen is displayed | |
expect(find.text('Welcome, testuser'), findsOneWidget); | |
expect(find.byType(Icon), findsOneWidget); // Example: Ensure there's an Icon on Home screen | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment