Flutter Driver 测试超时

Flutter Driver test timeout

我是 Flutter Driver 测试的新手,我遇到一个问题,即在等待小部件出现时测试总是超时(30 秒内)。我的主要 class 只是检查 Firebase 用户是否不为空。如果用户已登录,则显示仪表板,否则显示登录屏幕。 运行 检查时,它会显示启动画面。测试 "check flutter driver health" 正常完成。

我试过 find.byValueKey("auth_screen") 而不是 find.byType("AuthScreen"),它给出了同样的问题。

错误日志:

VMServiceFlutterDriver: Connected to Flutter application.
00:01 +0: rendin app check flutter driver health

HealthStatus.ok

00:01 +1: rendin app Check login screen widgets

Splash screen

VMServiceFlutterDriver: waitFor message is taking a long time to complete...
VMServiceFlutterDriver: waitFor message is taking a long time to complete...
00:31 +1 -1: rendin app Check login screen widgets [E]

  TimeoutException after 0:00:30.000000: Test timed out after 30 seconds.

    Bad state: The client closed with pending request "ext.flutter.driver".

这是我的测试代码:

import 'package:test/test.dart';
import 'package:flutter_driver/flutter_driver.dart';

import 'package:test/test.dart';

void main() {
  group('app', () {
    FlutterDriver driver;

    // Connect to the Flutter driver before running any tests.
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    test('check flutter driver health', () async {
      Health health = await driver.checkHealth();
      print(health.status);
    });

    test("Check login screen", () async {

      await driver.waitFor(find.byType("AuthScreen")).then((value) async {
        print("Auth screen");
      });
    });

    // Close the connection to the driver after the tests have completed.
    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });
  });
}

主要部分futureBuilder代码class:

builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
    if (snapshot.connectionState == ConnectionState.waiting) {
       return SplashScreen(key: Key("splashScreen2"));
    } else if (snapshot.hasData) {
       return DashboardScreen();
    } else {
       return AuthScreen();
    }
},

和 AuthScreen() 代码段:

class AuthScreen extends StatelessWidget {
  static const routeName = '/auth';

  @override
  Widget build(BuildContext context) {
    final deviceSize = MediaQuery.of(context).size;
    return Scaffold(
      key: Key("auth_screen"),
      backgroundColor: Colors.white,

test() 有一个名为 timeout

的参数

这是演示:

test("Check login screen", () async {

  await driver.waitFor(find.byType("AuthScreen")).then((value) async {
    print("Auth screen");
  });
}, timeout:Timeout.none);

哪个超时默认值 = 30 秒;