From 8298aa62726312eee6f8fbb64a9fc9b12680447f Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Thu, 17 Jun 2021 17:01:23 +0200 Subject: uitest: guard execute_blocking_action so even if an assert fails, the dialog is closed afterwards for motivation, see 89aaa17a0a4413f07da2bc5084b0164f15dc01ac < UITest: introduce guarded context managers > Change-Id: I9a3adb52546238d960eeaaaf03b6bdbbd5718cf8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117392 Tested-by: Jenkins Tested-by: Xisco Fauli Reviewed-by: Xisco Fauli --- uitest/uitest/test.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'uitest') diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py index cfa9b83e5a1c..c83759bf6b80 100644 --- a/uitest/uitest/test.py +++ b/uitest/uitest/test.py @@ -192,8 +192,8 @@ class UITest(object): if frames: frames[0].activate() - def execute_blocking_action(self, action, dialog_element=None, - args=(), dialog_handler=None, printNames=False): + @contextmanager + def execute_blocking_action(self, action, args=(), close_button="ok", printNames=False): """Executes an action which blocks while a dialog is shown. Click a button or perform some other action on the dialog when it @@ -202,11 +202,10 @@ class UITest(object): Args: action(callable): Will be called to show a dialog, and is expected to block while the dialog is shown. - dialog_element(str, optional): The name of a button on the dialog - which will be clicked when the dialog is shown. + close_button(str): The name of a button which will be clicked to close + the dialog. if it's empty, the dialog won't be closed from here. + This is useful when consecutive dialogs are open one after the other. args(tuple, optional): The arguments to be passed to `action` - dialog_handler(callable, optional): Will be called when the dialog - is shown, with the dialog object passed as a parameter. printNames: print all received event names """ @@ -217,15 +216,14 @@ class UITest(object): # we are not necessarily opening a dialog, so wait much longer while time_ < 10 * MAX_WAIT: if event.executed: - xDlg = self._xUITest.getTopFocusWindow() - if dialog_element: - xUIElement = xDlg.getChild(dialog_element) - xUIElement.executeAction("CLICK", tuple()) - if dialog_handler: - dialog_handler(xDlg) - thread.join() + xDialog = self._xUITest.getTopFocusWindow() + try: + yield xDialog + finally: + if close_button: + self.close_dialog_through_button(xDialog.getChild(close_button)) + thread.join() return - time_ += DEFAULT_SLEEP time.sleep(DEFAULT_SLEEP) raise DialogNotExecutedException("did not execute a dialog for a blocking action") -- cgit