Flutter Driver test timeout
Asked Answered
P

1

8

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,
Prescribe answered 17/3, 2020 at 16:33 Comment(6)
I don't know if this is related, but if you're awaiting something, you don't need to use .then()... await driver.waitFor(find.byType("AuthScreen"); print("done")Motch
^ I tested this and it doesn't seem to make a difference. What is the device showing when you run the tests?Motch
It shows a white screen, and then the app crashesPrescribe
That says that the test app isn't working as expected. Code you posted looks ok. Can you share the rest?Motch
I've shared a longer log message. Please let me know if that helps.Prescribe
Not particularly, the issue isn't with the test, that looks fine. If your app is crashing when running the test then you need to fix that before the test will pass.Motch
G
10

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;

Garlicky answered 24/4, 2020 at 8:8 Comment(2)
Thanks a lot! Spent the whole day trying to fix the bug.Lepidolite
api.flutter.dev/flutter/test_api/Timeout/none-constant.html it would be better to use noneMacmillan

© 2022 - 2024 — McMap. All rights reserved.