'Integration tests work fine from flutter drive, but hang when entering text in Firebase Test Lab

I have the following sign-in test set up for my app:

testWidgets('sign in with email and password', (WidgetTester tester) async {
  app.main();
  await tester.pumpAndSettle(Duration(seconds: 3));
  final emailInputFinder = find.byKey(Key('type-email'));
  final passwordInputFinder = find.byKey(Key('type-password'));
  final emailButtonFinder = find.byKey(Key('enter-email'));
  final passwordButtonFinder = find.byKey(Key('enter-password'));
  final dashboardFinder = find.byKey(Key('dashboard'));
  await tester.enterText(emailInputFinder, 'test.lab.user.01@...');
  await tester.pumpAndSettle(Duration(seconds: 3));
  await tester.tap(emailButtonFinder);
  await tester.pumpAndSettle(Duration(seconds: 3));
  await tester.enterText(passwordInputFinder, '...');
  await tester.pumpAndSettle(Duration(seconds: 3));
  await tester.tap(passwordButtonFinder);
  await tester.pumpAndSettle(Duration(seconds: 3));
  expect(dashboardFinder, findsOneWidget);
});

The hardcoded 3 second delay isn't ideal, but without it I can't run the tests using the driver.

Running on my local machine with the driver is fine. I use the command

flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart

But when I upload the Espresso test to Firebase Test Lab and review the video, the sign-in screen loads up, but the first enterText() command seems to have no effect. Nothing is added to the text field, and the test just times out.

I have tried various combinations of tester.tap() and tester.showKeyboard(), but so far, nothing is coming up.

How can I get enterText() to work correctly in the Espresso environment supported by TestLab?



Solution 1:[1]

Try calling binding.testTextInput.register():

  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;

// Necessary for being able to enterText when not in debug mode 
  binding.testTextInput.register();

There is an issue in the flutter repo about documenting this. Basically if you're not in debug mode you have to call binding.testTextInput.register() in order for tester.enterText to work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 croxx5f