Skip to content

[Flutter Driver] How to submit a TextField? #29450

Open

Description

@ciriousjoker

Steps to Reproduce

  1. Create a TextField inside the app with an onSubmitted handler.
  2. Write a driver test case that inputs text into it

(so far, this works flawlessly)

But now what, how can I submit the TextField to trigger onSubmitted without creating a separate UI element that does that when tapped?

[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.648], locale en-DE)
    • Flutter version 1.2.1 at G:\FlutterSDK
    • Framework revision 8661d8aecd (4 weeks ago), 2019-02-14 19:19:53 -0800
    • Engine revision 3757390fa4
    • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at G:\AndroidSDK
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = G:\AndroidSDK
    • Java binary at: G:\Program Files\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.3)
    • Android Studio at G:\Program Files\Android Studio
    • Flutter plugin version 33.3.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[√] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

Activity

  1. t-artikov commented on May 9, 2019

    @t-artikov

    @yjbanov @Hixie
    Any comments please?
    The use of FlutterDriver is quite limited without this feature.

  2. added
    t: flutter driver"flutter driver", flutter_drive, or a driver test
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    on May 11, 2019
  3. added this to the milestone on May 11, 2019
  4. yjbanov commented on May 18, 2019

    @yjbanov
    Contributor

    Would it be possible to use FlutterDriver.requestData and trigger the submission programmatically?

  5. t-artikov commented on May 18, 2019

    @t-artikov

    @yjbanov
    It's possible, I suppose, but it is not great if a user has to add application logic just for testing.
    It would be better if FlutterDriver was able to submit text input.

  6. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Dec 3, 2019
  7. removed
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jan 9, 2020
  8. khari998 commented on Apr 21, 2020

    @khari998

    Please add functionality for this in testing. I am having the same issue

  9. andrei1489 commented on May 13, 2020

    @andrei1489

    One workaround for this that I found is based on what @yjbanov said.

    You disable TextEntryEmulation, then on app side you register a new TestTextInput. Then back in the test, you tap on the input field, which triggers TextInput.setClient.

    app.dart :

    var textInput = TestTextInput();
    Function(String) handler = (message) {
         switch(message) {
          .......
           case 'typePassword':
            textInput.enterText("password");
            textInput.receiveAction(TextInputAction.done);
            textInput.unregister();
            break;
          case 'prepare':
            textInput.register();
            break;
           .......
          }
          enableFlutterDriverExtension(handler: handler);
    

    app_test.dart:

    .....
          await driver.setTextEntryEmulation(enabled: false);
          await driver.requestData("prepare");
          await driver.tap(passwordInput);
          await driver.requestData("typePassword");
    .....
    
  10. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  11. markusaksli-nc commented on Jul 29, 2020

    @markusaksli-nc
    Contributor

    This is probably going to be blocked until #9383 is done.

  12. removed this from the milestone on Aug 17, 2020
  13. Ibessas commented on Feb 18, 2021

    @Ibessas

    Any update?

  14. omatt commented on Aug 23, 2021

    @omatt
    Member

    Now that Flutter recommends writing integration tests with the integration_test package as mentioned in this doc, this feature might be less likely to be pushed any time soon.

    The workaround that I did was by using the integration_test package, following this post.

    import 'package:flutter/material.dart';
    import 'package:flutter_test/flutter_test.dart';
    import 'package:integration_test/integration_test.dart';
    import 'package:{YOUR_APP}/main.dart' as app;
    
    void main() {
      IntegrationTestWidgetsFlutterBinding.ensureInitialized();
    
      testWidgets("TextFormField Test", (WidgetTester tester) async {
        // Build the app and trigger a frame.
        await tester.pumpWidget(app.MyApp());
    
        /// Find TextFormField widget by Key and enter text
        await tester.enterText(find.byKey(Key('search-email-search-box')), '[email protected]');
        await tester.testTextInput.receiveAction(TextInputAction.done);
        await tester.pump();
    
        expect(find.text('[email protected]'), findsOneWidget);
      });
    }

    On the app:

    void onSearchEmail(String value){
      debugPrint('onSearchEmail $value');
    }
    
    ...
    
    TextFormField(
      key: Key('search-email-search-box'),
      textInputAction: TextInputAction.search,
      onFieldSubmitted: (String value) => onSearchEmail(value),
    ),
  15. hardik-kumbhani commented on Feb 18, 2022

    @hardik-kumbhani

    @omatt It's really works good for me Thanks

  16. dkwingsmt commented on Jul 15, 2022

    @dkwingsmt
    Contributor

    Now that #106561 has landed, is this issue completed?

  17. desmond206x commented on Sep 18, 2025

    @desmond206x

    It would be helpful to let the integration test run with the flutter run command to be faster, but it does not work because of text input isn't working. I test integration test for web in chrome if it helps..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.t: flutter driver"flutter driver", flutter_drive, or a driver testteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions