Flutter驱动程序测试超时

时间:2020-03-17 16:33:25

标签: android flutter dart flutterdriver

我是Flutter Driver测试的新手,但我遇到一个问题,即在等待小部件出现时测试总是超时(在30秒内)。我的主要课程仅检查Firebase用户是否不为null。如果用户已登录,则显示仪表板,否则显示登录屏幕。运行检查时,它会显示一个SplashScreen。测试“检查颤振驱动程序的运行状况”正常完成。

我尝试使用MessageHandler.handleMessage()而不是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".

主类中的futureBuilder代码片段:

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();
      }
    });
  });
}

和AuthScreen()代码段

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();
    }
},

1 个答案:

答案 0 :(得分:5)

test()有一个名为timeout

的参数

这里的演示:

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

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

哪个超时默认值为30秒;