2

I am writing an integration test using flutter_driver for searching using text field I have to enter(Keyboard Event) after entering text, I cannot find any solution to generate keyboard event in flutter_Driver, is there any solution to this?

test('search tests, search a user by name', () async {
      print('Waiting for join now button');
      print('search  test started');
      await driver.clearTimeline();
      print('pause for 5 sec');
      await Future.delayed(Duration(seconds: 5));
      print('Tapping search field');
      await driver.waitFor(searchbar.searchFieldFinder);
      await driver.tap(searchbar.searchFieldFinder);
      print('enter user searching');
      await driver.enterText('Test user');

      //**Enter Keyboard Event here**  

    }, timeout: Timeout(Duration(minutes: 2)));
Asif Nawaz
  • 80
  • 5

2 Answers2

4

For keyboard event ENTER in integration tests you can use this code:

  await tester.tap(find.byType(TextField));
  await tester.enterText(find.byType(TextField), text);
  await tester.testTextInput.receiveAction(TextInputAction.done);
  await tester.pumpAndSettle(Duration(seconds: 1));
mjablecnik
  • 182
  • 1
  • 14
0

I don't know if it applies to driver tests, but in widget tests you can use the tester.sendKeyDownEvent() function like so:

await tester.sendKeyDownEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();

I would imagine that it would translate over to driver tests like this:

await driver.sendKeyDownEvent(LogicalKeyboardKey.enter);
await driver.pumpAndSettle();
GroovinChip
  • 339
  • 4
  • 17