[py] fix flaky BiDi input tests that raced the page's autofocus - #17981
Open
AutomatedTester wants to merge 1 commit into
Open
[py] fix flaky BiDi input tests that raced the page's autofocus#17981AutomatedTester wants to merge 1 commit into
AutomatedTester wants to merge 1 commit into
Conversation
single_text_input.html focuses #textInput via autofocus. Firefox may apply that after the load event, so keys dispatched immediately after pages.load() can land on <body> and the leading characters get dropped. That is why the failure rotated between the keyboard tests in the file instead of pinning to one assertion.
test_combined_input_actions was affected too: the pointer and key sources advance tick-for-tick, so keyDown("t") fires alongside the pointer move, before the click that would have focused the input.
Request focus explicitly and wait for document.activeElement before performing actions, in both the generated _bidi mirror and the driver.input facade tests.
Fixes #17979
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.
Description
Fixes #17979.
common/src/web/single_text_input.htmlfocuses#textInputwith theautofocusattribute, and every keyboard test in the two BiDi input test files relied on that having taken effect by the timepages.load()returned. Firefox flushes autofocus candidates during the update-the-rendering steps, which can land after the load event, so keys dispatched immediately afterwards go to<body>and the leading characters are dropped.That explains the reported symptom — a different test failing on each run rather than one broken assertion. The affected tests are all and only the ones that load
single_text_input.html.test_combined_input_actionslooked immune because it clicks the input first, but it isn't: the pointer and key sources advance tick-for-tick, sokeyDown("t")fires in the same tick as the pointer move, one tick before the button press that would have focused the element. Its leadingtdepended on autofocus just like the others.Change
Added a
_load_single_text_input()helper to both files that loads the page, requests focus explicitly, and waits fordocument.activeElementto be the input before the test performs actions. The eight call sites in each file now use it. No production code changes; nothing about the actions under test changed.Applied to both
py/test/selenium/webdriver/common/_bidi/input_tests.py(the generated-command mirror named in the issue) andpy/test/selenium/webdriver/common/bidi/input_tests.py(thedriver.inputfacade tests), because the race is identical in both and fixing only one would just move the flake.test_wheel_scroll_with_durationis deliberately untouched — the issue notes it has a different cause and is being fixed separately.Verification
./scripts/format.shcould run — both need Bazel.ruff format --diffon the two files is clean, and both files compile.Reproducer to confirm once space is available:
bazel test //py:test/selenium/webdriver/common/_bidi/input_tests-firefox-bidi \ --pin_browsers=true --headless=true --local_test_jobs 1 \ --cache_test_results=no --runs_per_test=5and the same for
//py:test/selenium/webdriver/common/bidi/input_tests-firefox-bidi.Cross-binding impact
None to production code. Java, Ruby, .NET and JS have their own tests against
single_text_input.htmlthat make the same autofocus assumption; worth a follow-up issue if they show the same flake, but none was reported.AI disclosure
Root-cause analysis and the change were produced with Claude Code (per
CONTRIBUTING.md, disclosed here rather than in commit metadata). The reasoning above is mine to defend; the Bazel run that would back it is the outstanding gap noted under Verification.Types of changes
Checklist
Co-Authored-By: Copse noreply@copse.dev
Copse-Models: acp:claude-agent-acp#opus[1m]