summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-12-05 14:29:00 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2023-12-05 19:28:28 +0100
commitfaefc434efdc38587ddad0a65618efde81431e38 (patch)
tree6e38b09d9df21e277f45712bb4650a8b4c180bc6
parentFix apparent copy/paste typo (diff)
downloadcore-faefc434efdc38587ddad0a65618efde81431e38.tar.gz
core-faefc434efdc38587ddad0a65618efde81431e38.zip
Deduplicate execute_dialog_through_*
Use Python 3.3's 'yield from', which should be OK, because the baseline rhel8 has Python 3.6. If needed, older Python could use replacement like this: for dialog in self.wait_and_yield_dialog(event, xDialogParent, close_button): yield dialog Change-Id: Ic70bdf19fed730e41b7ce2868990ec88423eab33 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160352 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--uitest/uitest/test.py48
1 files changed, 19 insertions, 29 deletions
diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index 08c9a89ef9f5..db2bc1828be1 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -124,6 +124,23 @@ class UITest(object):
finally:
self.close_doc()
+ def wait_and_yield_dialog(self, event, parent, close_button):
+ while not event.executed:
+ time.sleep(DEFAULT_SLEEP)
+ dialog = self._xUITest.getTopFocusWindow()
+ if parent == dialog:
+ raise Exception("executing the action did not open the dialog")
+ try:
+ yield dialog
+ except:
+ if not close_button:
+ if 'cancel' in dialog.getChildren():
+ self.close_dialog_through_button(dialog.getChild("cancel"))
+ raise
+ finally:
+ if close_button:
+ self.close_dialog_through_button(dialog.getChild(close_button))
+
# Calls UITest.close_dialog_through_button at exit
@contextmanager
def execute_dialog_through_command(self, command, printNames=False, close_button = "ok", eventName = "DialogExecute"):
@@ -131,23 +148,7 @@ class UITest(object):
xDialogParent = self._xUITest.getTopFocusWindow()
if not self._xUITest.executeDialog(command):
raise Exception("Dialog not executed for: " + command)
- while True:
- if event.executed:
- xDialog = self._xUITest.getTopFocusWindow()
- if xDialogParent == xDialog:
- raise Exception("executing the action did not open the dialog")
- try:
- yield xDialog
- except:
- if not close_button:
- if 'cancel' in xDialog.getChildren():
- self.close_dialog_through_button(xDialog.getChild("cancel"))
- raise
- finally:
- if close_button:
- self.close_dialog_through_button(xDialog.getChild(close_button))
- return
- time.sleep(DEFAULT_SLEEP)
+ yield from self.wait_and_yield_dialog(event, xDialogParent, close_button)
@contextmanager
def execute_modeless_dialog_through_command(self, command, printNames=False, close_button = "ok"):
@@ -163,18 +164,7 @@ class UITest(object):
xDialogParent = self._xUITest.getTopFocusWindow()
with EventListener(self._xContext, event_name) as event:
ui_object.executeAction(action, parameters)
- while True:
- if event.executed:
- xDialog = self._xUITest.getTopFocusWindow()
- if xDialogParent == xDialog:
- raise Exception("executing the action did not open the dialog")
- try:
- yield xDialog
- finally:
- if close_button:
- self.close_dialog_through_button(xDialog.getChild(close_button))
- return
- time.sleep(DEFAULT_SLEEP)
+ yield from self.wait_and_yield_dialog(event, xDialogParent, close_button)
# Calls UITest.close_doc at exit
@contextmanager