androidflutterdartflutterdriver

Flutter Driver test timeout


I am new to Flutter Driver testing, and I have an issue that the tests always time out (in 30 seconds) while waiting for widgets to appear. My main class is only checking whether the Firebase user is not null. If a user is logged in, it is showing a dashboard, otherwise a login screen. While running the check, it is displaying a SplashScreen. The test "check flutter driver health" completes normally.

I tried find.byValueKey("auth_screen") instead of find.byType("AuthScreen"), it gives the same problem.

Error log:

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".

Here is my test code:

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

Piece of futureBuilder code in the main 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();
    }
},

and the AuthScreen() piece of code:

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,

Solution

  • test() has a param called timeout

    Here's demo:

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

    which timeout defaults value = 30 seconds;