Repository navigation
fix(uiautomator2): hideKeyboard confirms the keyboard hidden with two reads - #193
Merged
omnarayan merged 2 commits intoOct 3, 2026
Merged
Conversation
… reads A dumpsys read taken while the keyboard is still coming up can report it not shown, and Appium's hide_keyboard can answer 404 at the same moment, so the step returned without pressing BACK and the keyboard stayed over the next target. Treat the keyboard as hidden only when two reads 300 ms apart agree, both before and after Appium's call. BACK is still sent only while the keyboard is shown.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…board-race # Conflicts: # CHANGELOG.md
Contributor
|
Thanks @Lykhoyda! Confirming the keyboard is hidden with two reads makes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the UIAutomator2 driver,
hideKeyboarddecides whether the keyboard is up from a singledumpsys window InputMethodread. While the keyboard is still coming up, that read can report it not shown, and Appium'shide_keyboardcan answer HTTP 404 ("keyboard not present") at the same moment. The step then returns success without pressing BACK, and the keyboard stays over the next tap target.Evidence
In repeated QA runs of a flow that types into a field and then hides the keyboard, 1 run in 10 on 1.1.28 left the keyboard up after
hideKeyboard, so the next tap landed on the keyboard. The decision code is identical in 1.1.27.Fix
keyboardConfirmedHiddentreats the keyboard as hidden only when two reads 300 ms apart both say it is not shown.hideKeyboarduses it on the early-return path, andwaitKeyboardHiddenuses it after Appium's call. A read taken mid-transition can no longer skip the BACK fallback.Cost: each
hideKeyboardstep spends an extra 300 ms on the confirming read, including when the keyboard was already down.The 300 ms window narrows the race but cannot close it: a keyboard still not reported shown 300 ms later passes as hidden. A failing
dumpsysalso still reads as hidden, which predates this change.Tests
pkg/driver/uiautomator2/keyboard_hide_test.godriveshideKeyboardwith a scripted sequence ofdumpsysreads and Appium responses:hide_keyboardWithout the fix, the transition case returns "Keyboard not visible" with no BACK, and the stable-hidden case makes only one read. The 404-while-visible case passes on old code too: it guards the BACK path rather than reproducing the bug.
make fmt-check,go vet ./...andgo test -race ./...pass, except three tests that need a connected device or a free machine (pkg/deviceTestAndroidDevice_StartUIAutomator2, and twopkg/emulatortests that passed on rerun). Neither package imports the UIAutomator2 driver.