Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send "Key Pressed" events to native views #1937

Open
AlexanderFarkas opened this issue Nov 21, 2023 · 2 comments
Open

Send "Key Pressed" events to native views #1937

AlexanderFarkas opened this issue Nov 21, 2023 · 2 comments
Labels
feature New feature request P2 Issues not at the top of the work list package: patrol Related to the patrol package (native automation, test bundling)

Comments

@AlexanderFarkas
Copy link

AlexanderFarkas commented Nov 21, 2023

Use case

I wanted to enter text to a Stripe native card field.
I tried several methods:

  1. $.native.enterText
  2. $.enterText
  3. $.tester.sendKeyEvent for manual key typing.

Querying native views by Selector("card details") does work and it finds the card view, but enterText constantly failed.
Depending on what I tried it either failed with "Element doesn't have focus" or it failed to find element for enterText and silently crashed without error message even in verbose.

$.tester.sendKeyEvent - was evident workaround, but, turns out, it operates on Flutter layer and doesn't send keys to native views (it definitely didn't work for me).

So I decided to fork and add this functionality.

Final code:

await $(Keys.newCardField).tap(); // newCardField - is a key passed to CardField widget from StripeSDK
await $.pump(const Duration(seconds: 1)); // wait for focus

// manually tap text char by char
for (int i = 0; i < 11; i++) {
  await $.native.sendKeyEvent("4"); 
  await $.native.sendKeyEvent("2");
}
await $.native.sendKeyEvent("4");

Proposal

I'm not aware of the ability of inputing arbitrary characters on Android, but I've come up with the following API for iOS:

await $.native.sendKeyEvent("2");
@jBorkowska jBorkowska self-assigned this Nov 23, 2023
@jBorkowska jBorkowska added feature New feature request package: patrol Related to the patrol package (native automation, test bundling) P1 High-priority issues at the top of the work list labels Nov 23, 2023
@jBorkowska
Copy link
Collaborator

Hi @AlexanderFarkas! Thank you for this proposal, it would be awesome, if you opened a PR with your feature. Still, the Android part is needed, but you can open a PR anyway

@jBorkowska jBorkowska added P2 Issues not at the top of the work list and removed P1 High-priority issues at the top of the work list labels Nov 27, 2023
@AlexanderFarkas
Copy link
Author

@jBorkowska I will try to PR this week with Android version included

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request P2 Issues not at the top of the work list package: patrol Related to the patrol package (native automation, test bundling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants