Skip to content

Commit d1f886b

Browse files
martinpittmvollmer
authored andcommitted
test: Avoid scrolling race with session menu
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.
1 parent a9d06ef commit d1f886b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/common/testlib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ def mouse(
490490
ctrlKey: bool = False,
491491
shiftKey: bool = False,
492492
altKey: bool = False,
493-
metaKey: bool = False
493+
metaKey: bool = False,
494+
scrollVisible: bool = True,
494495
) -> None:
495496
"""Simulate a browser mouse event
496497
@@ -503,6 +504,7 @@ def mouse(
503504
:param shiftKey: press the shift key
504505
:param altKey: press the alt key
505506
:param metaKey: press the meta key
507+
:param scrollVisible: set to False in rare cases where scrolling an element into view triggers side effects
506508
"""
507509
self.wait_visible(selector)
508510

@@ -515,7 +517,7 @@ def mouse(
515517

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

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

0 commit comments

Comments
 (0)