testWidgets('Login Widget Testing', (WidgetTester tester) async {
await tester.pumpWidget(makeTestableWidget(Child: loginView));
Finder userNameField = find.byKey(Key('username'));
await tester.enterText(userNameField, 'demo');
Finder passwordField = find.byKey(Key('password'));
await tester.enterText(passwordField, 'welcome');
Finder licenceField = find.byKey(Key('licence'));
await tester.enterText(licenceField, 'demo');
await tester.tap(find.byKey(Key('btnLogin')));
final errorFinder = find.text(
'Invalid credentials Please check your credentials',
);
print(errorFinder);
expect(errorFinder, findsNothing);
});
onTap api gets call and validate wheather the user exist with above entered credential
- if user enters invalid credential expected to get error message 'Invalid credentials Please check your credentials'
- if entered valid credential should navigate to another page
Here now even though the credential is invalid it throws zero widgets with text "Invalid credentials Please check your credentials" (ignoring offstage widgets)
expected to have one widget
- if user enters invalid credential expected to get error message 'Invalid credentials Please check your credentials'
- if entered valid credential should navigate to another page
Here now even though the credential is invalid it throws zero widgets with text "Invalid credentials Please check your credentials" (ignoring offstage widgets)
expected to have one widget
await tester.pumpWidget(makeTestableWidget(Child: loginView));
Finder userNameField = find.byKey(Key('username'));
await tester.enterText(userNameField, 'd'emo);
Finder passwordField = find.byKey(Key('password'));
await tester.enterText(passwordField, 'welcome');
Finder licenceField = find.byKey(Key('licence'));
await tester.enterText(licenceField, 'demos');
var foo = find.byKey(Key('btnLogin'));
await tester.ensureVisible(foo); // <-- here
await tester.tap(foo);
await tester.pumpAndSettle();
final errorFinder = find.text(
'Invalid credentials Please check your credentials',
);
expect(errorFinder, findsOneWidget);
was expecting one widget with following text : 'Invalid credentials Please check your credentials'
Expected: exactly one matching node in the widget tree Actual: _TextFinder:<zero widgets with text "Invalid credentials Please check your credentials" (ignoring offstage widgets)> Which: means none were found but one was expected
//dart code https://drive.google.com/file/d/1wyemZGSP0rrLyMAAo00q4pdJ0nQf0ItX/view?usp=sharing