Asif Nawaz
Asif Nawaz

Reputation: 80

How to generate keyboard Event ENTER on a TextField in flutter_driver Tests

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

Upvotes: 2

Views: 1440

Answers (2)

GroovinChip
GroovinChip

Reputation: 375

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

Upvotes: 0

mjablecnik
mjablecnik

Reputation: 192

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

Upvotes: 5

Related Questions