uitest/uitest/test.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
New commits: commit 4edf1361ee8487ad69092d1fd4ba7defc3141474 Author: Neil Roberts <[email protected]> AuthorDate: Fri Nov 14 13:36:28 2025 +0100 Commit: Noel Grandin <[email protected]> CommitDate: Fri Nov 14 20:03:24 2025 +0100 UITest: Add a helper function to create an empty database Adds a method that creates a database document from the start center button similar to create_doc_in_start_center. Creating a database is a bit more involved because it first opens a dialog asking for details about the database. It also needs a filename immediately so a temporary file is created to store it. Change-Id: I3e5489ce539be0d9d9148b612b25da828866256f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194040 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py index 0ba35a98d9b9..915386dd7975 100644 --- a/uitest/uitest/test.py +++ b/uitest/uitest/test.py @@ -7,12 +7,14 @@ import time import threading +import tempfile from contextlib import contextmanager -from uitest.uihelper.common import get_state_as_dict +from uitest.uihelper.common import get_state_as_dict, select_by_text from com.sun.star.uno import RuntimeException from libreoffice.uno.eventlistener import EventListener +from libreoffice.uno.propertyvalue import mkPropertyValues DEFAULT_SLEEP = 0.1 @@ -189,6 +191,49 @@ class UITest(object): return time.sleep(DEFAULT_SLEEP) + # Creates an empty HSQLDB database with a temporary file name. On exit UITest.close_doc is + # called and the temporary file is deleted. + @contextmanager + def create_db_in_start_center(self): + # We have to give a filename to the database so let’s create a temporary one + with tempfile.NamedTemporaryFile(suffix=".odb") as temp: + with EventListener(self._xContext, "OnNew") as event: + xStartCenter = self._xUITest.getTopFocusWindow() + xBtn = xStartCenter.getChild("database_all") + with self.execute_dialog_through_action(xBtn, "CLICK", + close_button=None) as xDialog: + xDialog.getChild("createDatabase").executeAction("CLICK", tuple()) + select_by_text(xDialog.getChild("embeddeddbList"), "HSQLDB Embedded") + + xFinish = xDialog.getChild("finish") + + # Clicking finish will open a blocking dialog to set the filename + with self.execute_blocking_action(xFinish.executeAction, + ("CLICK", tuple()), + close_button=None) as xFileDialog: + xFileName = xFileDialog.getChild("file_name") + xFileName.executeAction("SET", mkPropertyValues({"TEXT": temp.name})) + + xOpen = xFileDialog.getChild("open") + + # Clicking the open button will trigger another blocking dialog because the + # file already exists and we have to confirm overwriting it + with self.execute_blocking_action(xOpen.executeAction, + ("CLICK", tuple()), + close_button="yes"): + pass + + while not event.executed: + time.sleep(DEFAULT_SLEEP) + + frames = self.get_frames() + self.get_desktop().setActiveFrame(frames[0]) + component = self.get_component() + try: + yield component + finally: + self.close_doc() + def close_dialog_through_button(self, button, dialog=None): if dialog is None: dialog = self._xUITest.getTopFocusWindow()
