Skip to content

Commit

Permalink
test: Avoid scrolling race with session menu
Browse files Browse the repository at this point in the history
The `<TopNav>` has a hackish `handleClickOutside()` that reacts to
any "blur" event anywhere on the menu. With the right timing (which
happens with `TestKerberos.testNegotiate` on our CI), opening the
session menu and scrolling a bit triggers a blur event, which closes the
menu again.

Avoid this by disabling the "scroll into view" part of the mouse click.
We don't need it in this case, as we just scrolled the session menu
opener itself in the previous step.
  • Loading branch information
martinpitt authored and mvollmer committed Nov 20, 2024
1 parent a9d06ef commit d1f886b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ def mouse(
ctrlKey: bool = False,
shiftKey: bool = False,
altKey: bool = False,
metaKey: bool = False
metaKey: bool = False,
scrollVisible: bool = True,
) -> None:
"""Simulate a browser mouse event
Expand All @@ -503,6 +504,7 @@ def mouse(
:param shiftKey: press the shift key
:param altKey: press the alt key
:param metaKey: press the meta key
:param scrollVisible: set to False in rare cases where scrolling an element into view triggers side effects
"""
self.wait_visible(selector)

Expand All @@ -515,7 +517,7 @@ def mouse(

# For Firefox and regular clicks, use the BiDi API, which is more realistic -- it doesn't
# sidestep the browser
element = self.call_js_func('ph_find_scroll_into_view', selector)
element = self.call_js_func('ph_find_scroll_into_view' if scrollVisible else 'ph_find', selector)

# btn=2 for context menus doesn't work with ph_mouse(); so translate the old ph_mouse() API
if event == "contextmenu":
Expand Down Expand Up @@ -1021,7 +1023,9 @@ def logout(self) -> None:
# happens when cockpit is still running
self.open_session_menu()
try:
self.click('#logout')
# HACK: scrolling into view sometimes triggers TopNav's handleClickOutside() hack
# we don't need it here, if the session menu is visible then so is the dropdown
self.mouse('#logout', "click", scrollVisible=False)
except RuntimeError as e:
# logging out does destroy the current frame context, it races with the CDP driver finishing the command
if "Execution context was destroyed" not in str(e):
Expand Down

0 comments on commit d1f886b

Please sign in to comment.