summaryrefslogtreecommitdiff
path: root/uitest
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2021-06-17 17:01:23 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-06-21 10:29:40 +0200
commit8298aa62726312eee6f8fbb64a9fc9b12680447f (patch)
treed35191b8bc0a48e0e086b19c9c3c0503e217c71b /uitest
parente837f50313a703b6b26abb78f224472c1e4734ea (diff)
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 <xiscofauli@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'uitest')
-rw-r--r--uitest/uitest/test.py26
1 files changed, 12 insertions, 14 deletions
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")