From 56beac6b04133c41c07a5cdd9886174c075c4260 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 6 Jul 2023 11:37:18 +0200 Subject: [PATCH] test: MakeBrowser.{focus,blur}() synchronous Calling .focus() and .blur() is asynchronous. When followed by key presses (which is the common use case for foucssing), this sometimes leads to typing the key presses somewhere else than the intended focussed element. To fix that, wait until the active element actually switched to the desired one. --- test/common/testlib.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/common/testlib.py b/test/common/testlib.py index d330d867e2a5..9bc426cca3b9 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -454,16 +454,18 @@ def focus(self, selector: str): :param selector: the selector """ - self.wait_visible(selector + ':not([disabled]):not([aria-disabled=true])') + self.wait_visible(f'{selector}:not([disabled]):not([aria-disabled=true])') self.call_js_func('ph_focus', selector) + self.wait_js_cond(f'document.activeElement == document.querySelector("{selector}")') def blur(self, selector: str): """Remove keyboard focus from selected element. :param selector: the selector """ - self.wait_visible(selector + ':not([disabled]):not([aria-disabled=true])') + self.wait_visible(f'{selector}:not([disabled]):not([aria-disabled=true])') self.call_js_func('ph_blur', selector) + self.wait_js_cond(f'document.activeElement != document.querySelector("{selector}")') # TODO: Unify them so we can have only one def key_press(self, keys: str, modifiers: int = 0, use_ord: bool = False):