7

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

我试过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 代码:

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,
4

1 回答 1

8

test()有一个参数叫做timeout

这是演示:

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

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

哪个超时默认值 = 30 秒;

于 2020-04-24T08:08:52.447 回答