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.");
    });
  });
}

这是错误截图: 在此处输入图像描述

当我执行此代码时,它正在运行自动化但给出错误并且测试失败。当我手动运行此应用程序时,仅在执行集成测试时才会出现此类错误。

请检查并告诉我这可能是什么解决方案。

提前致谢。

4

1 回答 1

0

看起来问题来自您的登录页面第 38 行(通过查看您的错误堆栈跟踪)

该错误是由您!对原为null. 您应该尝试在之前检查空值,而不是使用!. 例如

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

在这种情况下,编译器将为您提供帮助,因为!如果您检查可能的null. !(应该在你告诉你它不再需要的下方显示一条黄线)

于 2021-10-13T13:05:37.880 回答