leancodepl / patrol

Flutter-first UI testing framework. Ready for action!
https://patrol.leancode.co
Apache License 2.0
904 stars 139 forks source link

[package:patrol_finders] Keyboard can't be closed after `enterText` #2313

Closed RepliedSage11 closed 2 months ago

RepliedSage11 commented 3 months ago

Steps to reproduce

I am using only the patrol_finders package without patrol.

  1. Create an integration_test/bug_test.dart with the provided code sample.
    Code sample
import 'package:flutter/material.dart';
import 'package:patrol_finders/patrol_finders.dart';

void main() {
  patrolWidgetTest(
    'should enter text and close keyboard',
    (PatrolTester $) async {
      await $.pumpWidgetAndSettle(MaterialApp(
        home: Scaffold(
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                const TextField(),
                TextButton(
                  onPressed: () {
                    FocusManager.instance.primaryFocus?.unfocus();
                  },
                  child: const Text('Unfocus'),
                ),
              ],
            ),
          ),
        ),
      ));

      await $(TextField).tap();

      //enter text
      await $.enterText($(TextField), 'Hello');

      //unfocus
      await $(TextButton).tap();
    },
  );
}

  1. Run the integration test using flutter test integration_test/bug_test.dart on an iOS Simulator.

The test should enter the text into the field and close the keyboard due to losing focus.

Actual results

The test enters the text and loses focus but the keyboard is never closed.

Changing the line

await $.enterText($(TextField), 'Hello');

to use the WidgetTester method resolves the issue.

await $.tester.enterText($(TextField), 'Hello');

Logs

Logs ``` ```

Patrol version

patrol_finders: 2.1.2

Patrol Doctor output

Patrol Doctor output ``` ```

Flutter Doctor output

Flutter Doctor output ``` [✓] Flutter (Channel stable, 3.24.0, on macOS 14.5 23F79 darwin-arm64, locale en-GB) • Flutter version 3.24.0 on channel stable at /Users/alex/workspace/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 80c2e84975 (2 weeks ago), 2024-07-30 23:06:49 +0700 • Engine revision b8800d88be • Dart version 3.5.0 • DevTools version 2.37.2 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/alex/Library/Android/sdk • Platform android-34, build-tools 30.0.3 • ANDROID_HOME = /Users/alex/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2 [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.92.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (4 available) • Alex’s iPhone (mobile) • 00008130-001A310C0491401C • ios • iOS 17.6.1 21G93 • iPhone 15 Pro (mobile) • 32F931BC-1EE2-4379-B3F9-F81432A2FE9D • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
RepliedSage11 commented 3 months ago

It looks like the call to tester.testTextInput.register(); is the reason, although I know too little about the flutter_test package to know why.

Adding tester.testTextInput.unregister() after entering text seems to fix the immediate issue (but maybe breaks something else?).

jBorkowska commented 3 months ago

Hi @RepliedSage11, thank you for the issue - I reproduced it, it is a bug. Also your proposal of fix works, so I'll create a PR with this change.

tegankr commented 3 months ago

Hi, is there any chance the fix will be merged soon? It's impacting our delivery Thank you

github-actions[bot] commented 2 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue.