flutter_typeahead icon indicating copy to clipboard operation
flutter_typeahead copied to clipboard

Cannot "Tap" TypeAheadFormField in integration testing

Open Batflash5 opened this issue 3 years ago • 0 comments

When a TypeAheadFormField is tapped while in Integration Testing, the following error was thrown:

I/flutter (16571): (The following exception is now available via WidgetTester.takeException:) I/flutter (16571): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ I/flutter (16571): The following assertion was thrown running a test: I/flutter (16571): The finder "zero widgets with key [<'Zone'>] (ignoring offstage widgets)" (used in a call to I/flutter (16571): "tap()") could not find any matching widgets. I/flutter (16571): I/flutter (16571): When the exception was thrown, this was the stack: I/flutter (16571): #0 WidgetController._getElementPoint (package:flutter_test/src/controller.dart:897:7) I/flutter (16571): #1 WidgetController.getCenter (package:flutter_test/src/controller.dart:836:12) I/flutter (16571): #2 WidgetController.tap (package:flutter_test/src/controller.dart:271:18) I/flutter (16571): #3 main.. (file:///C:/Users/zzzz/AndroidStudioProjects/project1/integration_test/app_test.dart:29:20)

flutter doctor -v:

[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19042.867], locale en-IN) • Flutter version 2.2.3 at C:\flutter • Framework revision f4abaa0735 (3 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0) • Android SDK at C:\Users\zzz\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 51.0.1 • Dart plugin version 193.7547 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.54.1) • VS Code at C:\Users\zzz\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.16.0

[√] Connected device (3 available) • CPH2001 (mobile) • WSBQYPPRYSYHCULZ • android-arm64 • Android 11 (API 30) • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.164 • Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.70

• No issues found!

Minimal Reproducible Code:

main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';

void main() => runApp(HomePage());

class HomePage extends StatelessWidget {

  List<String> numbers=["1","2","3","4"];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: TypeAheadFormField(
            key: Key("Zone"),
            itemBuilder: (context,suggestion){
              return Text(
                  suggestion
              );
            },
            onSuggestionSelected: (suggestion){
              print(suggestion);
            },
            suggestionsCallback: (pattern){
              return numbers;
            },
          ),
        ),
      ),
    );
  }
}

Testing Code: project1/integration_test/app_test.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:project1/main.dart' as app;

void main(){
  group("Integration Testing",(){

    IntegrationTestWidgetsFlutterBinding.ensureInitialized();

    testWidgets("Integration test for TypeAheadFormField", (tester)async{

      app.main();

      Finder zoneField=find.byKey(Key("Zone")); //finding zone's TypeAheadFormField by key.
      await tester.tap(zoneField); //This is where the issue raises.

      await tester.pumpAndSettle();

    });

  });
}

Test Driver: project1/test_driver/integration_test_driver.dart

import 'package:integration_test/integration_test_driver_extended.dart';

void main() =>integrationDriver();

Batflash5 avatar Jul 21 '21 11:07 Batflash5