0
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:integration_test/integration_test.dart';
import 'package:knights_bridge/main.dart' as app;
import 'dart:io';
import 'package:knights_bridge/screens/shared/bigButtonFilled.dart';

void main() {
  group('Sign in test', () {
    IntegrationTestWidgetsFlutterBinding.ensureInitialized();
    testWidgets('Validate sign in and dashboard', (tester) async {
      app.main();

      await tester.pumpAndSettle();
      final emailField = find.byKey(Key('login'));
      final passwordField = find.byKey(Key('password'));
      final signInButton = find.text('Sign in');
      // final signInButton = find.byType(BigFilledButton);

      print("Starting typing in email field");
      await tester.enterText(emailField, "ashiq@gmail.com");

      print("Starting typing in password field");
      await tester.enterText(passwordField, "123456789As@");

      await tester.pumpAndSettle();
      print("Clicking on sign in button");
      await tester.tap(signInButton);

      await tester.pumpAndSettle();
      final signInMessage = find.text("Login successful");

      print("Started verifying the message for successful login.");
      await tester.ensureVisible(signInMessage);
      await tester.pumpAndSettle(Duration(seconds: 4));

      print("Successfully the success message in dashboard.");
    });
  });
}

Here is the error screenshot: enter image description here

When I'm executing this code it is running the automation but giving an error and test is failing. There are no such error raising while I'm running this app manually only raising when executing integration test.

Please check and tell me what's could be the solution for this.

Thanks in advance.

ssharkar
  • 57
  • 6
  • Please add the source code that you're testing, since that will be the place where you are using a null check operator on a null value. – James Oct 13 '21 at 12:04
  • Unfortunately I can't share the source code here as it's an NDA site. Give me some suggestion about where should I look for the issue. There is no problem while running the app manually, no error messages. – ssharkar Oct 13 '21 at 12:46
  • That does make asking on SO very hard so I'd see if you can ask your employer/owner of code about how much you can post in future. I'll try to give my best answer in an answer below – James Oct 13 '21 at 13:01

1 Answers1

0

Looks like the issue comes from your login page line 38 (from looking at your error stack trace)

The error is caused by you using a null-check-operator ! on a value which was null. You should try and check for a null value before instead of using the !. e.g.

if(possiblyNullValue == null){
  do something
} else {
  do the thing you wanted with possiblyNullValue
}

The compiler will help you in this case as your code should no longer need the ! operator if you check for the possible null. (should show a yellow line under your ! telling you it isn't needed anymore)

James
  • 2,516
  • 2
  • 19
  • 31