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

385

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));
Share:
385
Asif Nawaz
Author by

Asif Nawaz

Updated on December 01, 2022

Comments

  • Asif Nawaz
    Asif Nawaz over 1 year

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