mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.71k stars 260 forks source link

Fix input text speed on Android #2027

Open tokou opened 2 weeks ago

tokou commented 2 weeks ago

Proposed changes

The speedup is amazing 🤩

Testing

Before After
input_text_old input_text

Issues fixed

Fixes #2005

bartekpacia commented 2 weeks ago

Hey @tokou! Thanks a ton for taking a stab and fixing this very annoying problem.

The speedup is amazing indeed, but I'm not sure if we want it, given that we want Maestro to behave like a normal user. Anyway, we could make this new behavior the default, and add a configuration option for inputText (for command and workspace level) in the future if someone requests the old way of how inputText worked (i.e. entering text character-by-character).

I like all the changes you made in this PR, but I'm curious whether you know what's the change that actually fixed the problem? Was it the removal of that Thread.sleep(75)?

bartekpacia commented 2 weeks ago

I like the test that inputs the whole "Lorem ipsum...". If that test also used assertVisible at the end, that'd be a pretty solid test that inputText works well and is stable.

I'd like us to have this test in our demo_app workspace.

I'll add such a screen to our demo app.

bartekpacia commented 2 weeks ago

Oh, and let's also add an entry to CHANGELOG.md

Leland-Takamine commented 2 weeks ago

Nice work on this! Some context on the delays added in the original implementation: We were seeing some issues where sometimes characters would be skipped. This was difficult to reproduce consistently, but we should ensure that this does not regress before making this the default behavior.

tokou commented 1 week ago

@bartekpacia I added the comment. Hope it clears things up. I also redid testing with the 3 cases : old, just removing the sleep and sending bunched up key presses

Old (00:54) No sleep (00:24) Bunch keys (00:17)
input_text_old input_text_no_sleep input_text_bunch

@Leland-Takamine

We were seeing some issues where sometimes characters would be skipped.

I think this is due to the rate of commands sent to UiDevice. That's why the bunching up of commands through pressKeyCodes could be better than just blasting n calls to pressKeyCode

The only potential issue is that the documentation of pressKeyCodes states that it's more intended for multiple key presses at the same time instead of consecutive key presses 🤔

pressKeyCodes Presses one or more keys. For example, you can simulate taking a screenshot on the device by pressing both the power and volume down keys.

— https://developer.android.com/reference/androidx/test/uiautomator/UiDevice#pressKeyCodes(int[],int)

In practice, it seems to be working fine though.

tokou commented 1 week ago

@bartekpacia Unfortunately, after adding the test on the demo app, I got some random failures when running it on my emulator. I think it's in part because of the demo app being a Flutter app that makes the issue happen more often.

amanjeetsingh150 commented 1 week ago

Hey @tokou is this PR ready for review? I see that you observed some random failures, let me know if you need help on this.