appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
454 stars 183 forks source link

Simulating Keyboard Events #246

Open marcosmko opened 2 years ago

marcosmko commented 2 years ago

Hello!

I'm using this plugin but it seems I cannot simulate some keyboard events like pressing enter. I would like to know if there is a way for that.

I have tried using (python library):

# native context
driver.press_keycode(66)

and

# native context
element.send_keys('\n')

and

# flutter context
driver.execute_script('flutter:enterText', '\n')

But it didn't work.

Using the new package integration_test for creating tests, I can simulate keyboard events:

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  testWidgets('typing text', (WidgetTester tester) async {
    await app.main();
    await tester.pumpAndSettle(const Duration(seconds: 1));

    // Tap on textfield
    final Finder textfield = find.text('textfield');
    await tester.tap(textfield, warnIfMissed: false);

    // Enter some text and press done button
    final TestTextInput keyboard = tester.testTextInput;
    keyboard.enterText('some text');
    await keyboard.receiveAction(TextInputAction.done);
  });
}

As integration_test package also uses flutter_driver to drive app, I suppose it is possible to simulate those events, is it?

KazuCocoa commented 2 years ago

I haven't dug integration_test internal code, but if flutter_driver package also had the same code, they should work as same. (But both behavior depends on Flutter code, not this repository's one)

KazuCocoa commented 2 years ago

driver.press_keycode(66) for android sends key events to the Android OS via UiObject as https://developer.android.com/reference/android/view/KeyEvent So, probably it depends on how flutter handles UiObject events internally.

KazuCocoa commented 1 year ago

I just wondered if the native context could work after calling driver.execute('flutter:setTextEntryEmulation', false) https://api.flutter.dev/flutter/flutter_driver/FlutterDriver/setTextEntryEmulation.html

Tanvi-Sawant commented 1 year ago

@KazuCocoa I am getting Appium error: An unknown server-side error occurred while processing the command. Original error: Command not support: "flutter:setTextEntryEmulation".

KazuCocoa commented 1 year ago

What version of driver did you use? Please try out the latest version with Appium 2 if not tried it out yet

slrongji commented 1 year ago

anything new here? Appium 2 is used . but did not manage to simulate keyEnter.

slrongji commented 1 year ago

await tester.testTextInput.receiveAction(TextInputAction.done);

https://api.flutter.dev/flutter/flutter_driver/SendTextInputAction-class.html flutter driver provide such command

done → const TextInputAction Logical meaning: The user is done providing input to a group of inputs (like a form). Some kind of finalization behavior should now take place.

Android: Corresponds to Android's "IME_ACTION_DONE". The OS displays a button that represents completion, e.g., a checkmark button.

iOS: Corresponds to iOS's "UIReturnKeyDone". The title displayed in the action button is "Done".

But if using flutter appium driver driver.executeScript("flutter:sendTextInputAction","IME_ACTION_DONE", timeOutMilliSecond); it will give error

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Command not support: "flutter:sendTextInputAction"

KazuCocoa commented 1 year ago

Then, it is not implemented yet https://github.com/appium-userland/appium-flutter-driver#commands Feel free to create a PR

anu-rachel commented 1 year ago

How to simulate the keyboard ENTER event using flutter driver while testing (since keyboard is disabled)? await driver.execute('flutter:sendTextInputAction', 'IME_ACTION_DONE') - is this correct? Got an error : unknown error: An unknown server-side error occurred while processing the command. Original error: Command not support: "flutter:sendTextInputAction"
at processTicksAndRejections (node:internal/process/task_queues:95:5) Could you please provide an update?

nanguaSky commented 12 months ago

can use follow code instead of driver.press_keycode subprocess.run(["adb", "shell", "input", "keyevent", "66"], capture_output=True, text=True, check=True)

nanguaSky commented 12 months ago

How to simulate the keyboard ENTER event using flutter driver while testing (since keyboard is disabled)? await driver.execute('flutter:sendTextInputAction', 'IME_ACTION_DONE') - is this correct? Got an error : unknown error: An unknown server-side error occurred while processing the command. Original error: Command not support: "flutter:sendTextInputAction" at processTicksAndRejections (node:internal/process/task_queues:95:5) Could you please provide an update?

subprocess.run(["adb", "shell", "input", "keyevent", "66"], capture_output=True, text=True, check=True) is worked