[Libreoffice-commits] core.git: cui/qa sfx2/qa svx/qa uitest/demo_ui uitest/impress_tests uitest/uitest

Xisco Fauli (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 29 11:27:04 UTC 2021


 cui/qa/uitest/dialogs/chardlg.py       |   60 ++++++++++++++-------------------
 cui/qa/uitest/dialogs/pastedlg.py      |   29 +++++++--------
 cui/qa/uitest/dialogs/shortcuts.py     |   23 +++++-------
 sfx2/qa/uitest/doc/objserv.py          |   11 ++----
 svx/qa/uitest/table/tablecontroller.py |   28 ++++++---------
 uitest/demo_ui/char_dialog.py          |    9 +---
 uitest/demo_ui/checkbox.py             |    9 +---
 uitest/demo_ui/hierarchy.py            |   15 +++-----
 uitest/demo_ui/listbox.py              |   14 ++-----
 uitest/demo_ui/radiobutton.py          |    9 +---
 uitest/demo_ui/spinfield.py            |   47 ++++++++++---------------
 uitest/demo_ui/tabdialog.py            |   14 ++-----
 uitest/impress_tests/backgrounds.py    |   30 ++++++----------
 uitest/impress_tests/drawinglayer.py   |   46 +++++++------------------
 uitest/uitest/uihelper/common.py       |   59 ++++++++++++++------------------
 uitest/uitest/uihelper/testDialog.py   |   28 ++++++---------
 16 files changed, 172 insertions(+), 259 deletions(-)

New commits:
commit 8fe4a2cb1ad3b4819e069179cc11430c5127613c
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Tue Jun 29 11:35:20 2021 +0200
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Tue Jun 29 13:26:30 2021 +0200

    uitest: guard remaining execute_dialog_through_command
    
    Mostly done with a script
    for motivation, see 89aaa17a0a4413f07da2bc5084b0164f15dc01ac
    < UITest: introduce guarded context managers >
    
    Change-Id: Ib8e7c5f5e2c9b8a7756fe533ea4f30349dd68761
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118076
    Tested-by: Xisco Fauli <xiscofauli at libreoffice.org>
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/cui/qa/uitest/dialogs/chardlg.py b/cui/qa/uitest/dialogs/chardlg.py
index fb1c1286cbae..e2c518d18ef3 100644
--- a/cui/qa/uitest/dialogs/chardlg.py
+++ b/cui/qa/uitest/dialogs/chardlg.py
@@ -25,15 +25,13 @@ class Test(UITestCase):
         self.xUITest.executeCommand(".uno:SelectAll")
 
         # Now use Format -> Character.
-        self.ui_test.execute_dialog_through_command(".uno:FontDialog")
-        xDialog = self.xUITest.getTopFocusWindow()
-        xTabs = xDialog.getChild("tabcontrol")
-        # Select RID_SVXPAGE_CHAR_EFFECTS.
-        select_pos(xTabs, "1")
-        xFontTransparency = xDialog.getChild("fonttransparencymtr")
-        for _ in range(5):
-            xFontTransparency.executeAction("UP", tuple())
-        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FontDialog") as xDialog:
+            xTabs = xDialog.getChild("tabcontrol")
+            # Select RID_SVXPAGE_CHAR_EFFECTS.
+            select_pos(xTabs, "1")
+            xFontTransparency = xDialog.getChild("fonttransparencymtr")
+            for _ in range(5):
+                xFontTransparency.executeAction("UP", tuple())
 
         # Verify the result.
         component = self.ui_test.get_component()
@@ -58,19 +56,17 @@ class Test(UITestCase):
         self.xUITest.executeCommand(".uno:SelectAll")
 
         # Now use Format -> Character.
-        self.ui_test.execute_dialog_through_command(".uno:FontDialog")
-        xDialog = self.xUITest.getTopFocusWindow()
-        xTabs = xDialog.getChild("tabcontrol")
-        # Select RID_SVXPAGE_CHAR_EFFECTS.
-        select_pos(xTabs, "1")
-        xFontTransparency = xDialog.getChild("fonttransparencymtr")
-        # Without the accompanying fix in place, this test would have failed with:
-        # AssertionError: 'false' != 'true'
-        # i.e. the transparency widget was hidden.
-        self.assertEqual(get_state_as_dict(xFontTransparency)["Visible"], "true")
-        for _ in range(5):
-            xFontTransparency.executeAction("UP", tuple())
-        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FontDialog") as xDialog:
+            xTabs = xDialog.getChild("tabcontrol")
+            # Select RID_SVXPAGE_CHAR_EFFECTS.
+            select_pos(xTabs, "1")
+            xFontTransparency = xDialog.getChild("fonttransparencymtr")
+            # Without the accompanying fix in place, this test would have failed with:
+            # AssertionError: 'false' != 'true'
+            # i.e. the transparency widget was hidden.
+            self.assertEqual(get_state_as_dict(xFontTransparency)["Visible"], "true")
+            for _ in range(5):
+                xFontTransparency.executeAction("UP", tuple())
 
         # Verify the result.
         component = self.ui_test.get_component()
@@ -86,18 +82,16 @@ class Test(UITestCase):
         editWin = doc.getChild("writer_edit")
 
         # Use Format -> Character.
-        self.ui_test.execute_dialog_through_command(".uno:FontDialog")
-        xDialog = self.xUITest.getTopFocusWindow()
-        xTabs = xDialog.getChild("tabcontrol")
-        # Select RID_SVXPAGE_CHAR_EFFECTS.
-        select_pos(xTabs, "1")
-        xFontColorLB = xDialog.getChild("fontcolorlb")
-        # Without the accompanying fix in place, this test would have failed with:
-        # AssertionError: 'White' != 'Automatic'
-        # i.e. the auto color lost its alpha component and appeared as white.
-        self.assertEqual(get_state_as_dict(xFontColorLB)["Text"], "Automatic")
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FontDialog") as xDialog:
+            xTabs = xDialog.getChild("tabcontrol")
+            # Select RID_SVXPAGE_CHAR_EFFECTS.
+            select_pos(xTabs, "1")
+            xFontColorLB = xDialog.getChild("fontcolorlb")
+            # Without the accompanying fix in place, this test would have failed with:
+            # AssertionError: 'White' != 'Automatic'
+            # i.e. the auto color lost its alpha component and appeared as white.
+            self.assertEqual(get_state_as_dict(xFontColorLB)["Text"], "Automatic")
 
-        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
         self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/cui/qa/uitest/dialogs/pastedlg.py b/cui/qa/uitest/dialogs/pastedlg.py
index 9ac40c55d2b6..048463286003 100644
--- a/cui/qa/uitest/dialogs/pastedlg.py
+++ b/cui/qa/uitest/dialogs/pastedlg.py
@@ -26,22 +26,19 @@ class Test(UITestCase):
         self.xUITest.executeCommand(".uno:Copy")
 
         # Now use paste special to see what formats are offered.
-        self.ui_test.execute_dialog_through_command(".uno:PasteSpecial")
-        pasteSpecial = self.xUITest.getTopFocusWindow()
-        formats = pasteSpecial.getChild("list")
-        entryCount = int(get_state_as_dict(formats)["Children"])
-        items = []
-        for index in range(entryCount):
-            entry = formats.getChild(str(index))
-            entry.executeAction("SELECT", tuple())
-            items.append(get_state_as_dict(formats)["SelectEntryText"])
-
-        # Make sure there is no RTF vs Richtext duplication.
-        self.assertTrue("Rich text formatting (RTF)" in items)
-        self.assertFalse("Rich text formatting (Richtext)" in items)
-
-        # Close the dialog and the document.
-        self.ui_test.close_dialog_through_button(pasteSpecial.getChild("cancel"))
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:PasteSpecial", close_button="cancel") as pasteSpecial:
+            formats = pasteSpecial.getChild("list")
+            entryCount = int(get_state_as_dict(formats)["Children"])
+            items = []
+            for index in range(entryCount):
+                entry = formats.getChild(str(index))
+                entry.executeAction("SELECT", tuple())
+                items.append(get_state_as_dict(formats)["SelectEntryText"])
+
+            # Make sure there is no RTF vs Richtext duplication.
+            self.assertTrue("Rich text formatting (RTF)" in items)
+            self.assertFalse("Rich text formatting (Richtext)" in items)
+
         self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/cui/qa/uitest/dialogs/shortcuts.py b/cui/qa/uitest/dialogs/shortcuts.py
index 8a52ee42315a..7f3f9337a525 100644
--- a/cui/qa/uitest/dialogs/shortcuts.py
+++ b/cui/qa/uitest/dialogs/shortcuts.py
@@ -17,26 +17,23 @@ class Test(UITestCase):
         xWriterDoc = self.xUITest.getTopFocusWindow()
         xWriterEdit = xWriterDoc.getChild("writer_edit")
 
-        self.ui_test.execute_dialog_through_command(".uno:EditStyle")  #open style dialog
-        xDialog = self.xUITest.getTopFocusWindow()
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:EditStyle") as xDialog:
 
-        xTabs = xDialog.getChild("tabcontrol")
-        select_pos(xTabs, "0")
+            xTabs = xDialog.getChild("tabcontrol")
+            select_pos(xTabs, "0")
 
-        for i in range(16):
-            self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
+            for i in range(16):
+                self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
 
-            xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEDOWN"}))
+                xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEDOWN"}))
 
-        self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], "0")
+            self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], "0")
 
-        for i in reversed(range(16)):
-            xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEUP"}))
+            for i in reversed(range(16)):
+                xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEUP"}))
 
-            self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
+                self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
 
-        xOkBtn = xDialog.getChild("ok")
-        xOkBtn.executeAction("CLICK", tuple())
 
         self.ui_test.close_doc()
 
diff --git a/sfx2/qa/uitest/doc/objserv.py b/sfx2/qa/uitest/doc/objserv.py
index 7c658be8dfd8..67c4765d4840 100644
--- a/sfx2/qa/uitest/doc/objserv.py
+++ b/sfx2/qa/uitest/doc/objserv.py
@@ -14,14 +14,11 @@ class Test(UITestCase):
     def testPdfSigning(self):
         # Start Impress.
         with self.ui_test.load_file(get_url_for_data_file("pdf-sign.pdf")) as impress_doc:
-            doc = self.xUITest.getTopFocusWindow()
 
             # Now use File -> Digital signatures -> Digital signatures.
-            self.ui_test.execute_dialog_through_command(".uno:Signature")
-            xDialog = self.xUITest.getTopFocusWindow()
-            # Without the accompanying fix in place, this test would have failed with:
-            # uno.com.sun.star.uno.RuntimeException: Could not find child with id: close vcl/source/uitest/uiobject.cxx:452
-            self.ui_test.close_dialog_through_button(xDialog.getChild("close"))
-
+            with self.ui_test.execute_dialog_through_command_guarded(".uno:Signature", close_button="close"):
+                # Without the accompanying fix in place, this test would have failed with:
+                # uno.com.sun.star.uno.RuntimeException: Could not find child with id: close vcl/source/uitest/uiobject.cxx:452
+                pass
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/svx/qa/uitest/table/tablecontroller.py b/svx/qa/uitest/table/tablecontroller.py
index 607df44a3a4f..1b6989f039dd 100644
--- a/svx/qa/uitest/table/tablecontroller.py
+++ b/svx/qa/uitest/table/tablecontroller.py
@@ -22,14 +22,12 @@ class SvxTableControllerTest(UITestCase):
         self.xUITest.executeCommand(".uno:InsertTable?Columns:short=2&Rows:short=2")
 
         # Enable shadow.
-        self.ui_test.execute_dialog_through_command(".uno:TableDialog")
-        tableDialog = self.xUITest.getTopFocusWindow()
-        tabs = tableDialog.getChild("tabcontrol")
-        # Select "shadow".
-        select_pos(tabs, "4")
-        shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
-        shadowCheckbox.executeAction("CLICK", tuple())
-        self.ui_test.close_dialog_through_button(tableDialog.getChild("ok"))
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:TableDialog") as tableDialog:
+            tabs = tableDialog.getChild("tabcontrol")
+            # Select "shadow".
+            select_pos(tabs, "4")
+            shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
+            shadowCheckbox.executeAction("CLICK", tuple())
 
         # Check if the shadow was enabled.
         component = self.ui_test.get_component()
@@ -61,14 +59,12 @@ class SvxTableControllerTest(UITestCase):
             impress.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+TAB"}))
         impress.executeAction("TYPE", mkPropertyValues({"TEXT": "A3"}))
         self.xUITest.executeCommand(".uno:SelectAll")
-        self.ui_test.execute_dialog_through_command(".uno:TableDialog")
-        tableDialog = self.xUITest.getTopFocusWindow()
-        tabs = tableDialog.getChild("tabcontrol")
-        # Select "shadow".
-        select_pos(tabs, "4")
-        shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
-        shadowCheckbox.executeAction("CLICK", tuple())
-        self.ui_test.close_dialog_through_button(tableDialog.getChild("ok"))
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:TableDialog") as tableDialog:
+            tabs = tableDialog.getChild("tabcontrol")
+            # Select "shadow".
+            select_pos(tabs, "4")
+            shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
+            shadowCheckbox.executeAction("CLICK", tuple())
 
         # Then make sure we don't crash:
         # Without the accompanying fix in place, this test would have failed crashed due to a
diff --git a/uitest/demo_ui/char_dialog.py b/uitest/demo_ui/char_dialog.py
index 5dd0212ee719..3b7083b1dba1 100644
--- a/uitest/demo_ui/char_dialog.py
+++ b/uitest/demo_ui/char_dialog.py
@@ -13,15 +13,12 @@ class CharDialogText(UITestCase):
     def test_select_char(self):
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:InsertSymbol")
-        xCharDialog = self.xUITest.getTopFocusWindow()
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:InsertSymbol", close_button="cancel") as xCharDialog:
 
-        xCharSet = xCharDialog.getChild("showcharset")
+            xCharSet = xCharDialog.getChild("showcharset")
 
-        xCharSet.executeAction("SELECT", mkPropertyValues({"COLUMN": "2", "ROW": "2"}))
+            xCharSet.executeAction("SELECT", mkPropertyValues({"COLUMN": "2", "ROW": "2"}))
 
-        xCancelBtn = xCharDialog.getChild("cancel")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
 
         self.ui_test.close_doc()
 
diff --git a/uitest/demo_ui/checkbox.py b/uitest/demo_ui/checkbox.py
index 114473d53851..ffee343bf50b 100644
--- a/uitest/demo_ui/checkbox.py
+++ b/uitest/demo_ui/checkbox.py
@@ -15,13 +15,10 @@ class CheckBoxTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
-        xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
-        xNegativeNumRedCB.executeAction("CLICK",tuple())
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog") as xCellsDlg:
+            xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
+            xNegativeNumRedCB.executeAction("CLICK",tuple())
 
-        okBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(okBtn)
 
         self.ui_test.close_doc()
 
diff --git a/uitest/demo_ui/hierarchy.py b/uitest/demo_ui/hierarchy.py
index f5434366fda4..73c15bb607e1 100644
--- a/uitest/demo_ui/hierarchy.py
+++ b/uitest/demo_ui/hierarchy.py
@@ -17,18 +17,15 @@ class CheckBoxTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:About")
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:About", close_button="btnClose") as xAboutDlg:
 
-        xAboutDlg = self.xUITest.getTopFocusWindow()
 
-        json_string = xAboutDlg.getHierarchy()
-        print(json_string)
-        json_content = json.loads(json_string)
-        print(json_content)
-        print(json.dumps(json_content, indent=4))
+            json_string = xAboutDlg.getHierarchy()
+            print(json_string)
+            json_content = json.loads(json_string)
+            print(json_content)
+            print(json.dumps(json_content, indent=4))
 
-        closeBtn = xAboutDlg.getChild("btnClose")
-        self.ui_test.close_dialog_through_button(closeBtn)
 
         self.ui_test.close_doc()
 
diff --git a/uitest/demo_ui/listbox.py b/uitest/demo_ui/listbox.py
index 7e9ae16e6543..9784178d20a7 100644
--- a/uitest/demo_ui/listbox.py
+++ b/uitest/demo_ui/listbox.py
@@ -16,11 +16,8 @@ class ListBoxTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
-
-        xOkBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOkBtn)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog"):
+            pass
 
         self.ui_test.close_doc()
 
@@ -28,11 +25,8 @@ class ListBoxTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
-
-        xOkBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOkBtn)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog"):
+            pass
 
         self.ui_test.close_doc()
 
diff --git a/uitest/demo_ui/radiobutton.py b/uitest/demo_ui/radiobutton.py
index bb2f5bd07440..f3331fa18863 100644
--- a/uitest/demo_ui/radiobutton.py
+++ b/uitest/demo_ui/radiobutton.py
@@ -27,13 +27,10 @@ class RadioButtonTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
-        xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
-        xNegativeNumRedCB.executeAction("CLICK",tuple())
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog") as xCellsDlg:
+            xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
+            xNegativeNumRedCB.executeAction("CLICK",tuple())
 
-        okBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(okBtn)
 
         self.ui_test.close_doc()
 
diff --git a/uitest/demo_ui/spinfield.py b/uitest/demo_ui/spinfield.py
index a74e47206274..a0e983ea81b6 100644
--- a/uitest/demo_ui/spinfield.py
+++ b/uitest/demo_ui/spinfield.py
@@ -16,17 +16,14 @@ class SpinFieldTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog") as xCellsDlg:
 
-        xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
-        xDecimalPlaces.executeAction("UP", tuple())
+            xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
+            xDecimalPlaces.executeAction("UP", tuple())
 
-        decimal_places_state = get_state_as_dict(xDecimalPlaces)
-        assert(decimal_places_state["Text"] == "2")
+            decimal_places_state = get_state_as_dict(xDecimalPlaces)
+            assert(decimal_places_state["Text"] == "2")
 
-        okBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(okBtn)
 
         self.ui_test.close_doc()
 
@@ -34,23 +31,20 @@ class SpinFieldTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog") as xCellsDlg:
 
-        xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
-        xDecimalPlaces.executeAction("UP", tuple())
-        xDecimalPlaces.executeAction("UP", tuple())
+            xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
+            xDecimalPlaces.executeAction("UP", tuple())
+            xDecimalPlaces.executeAction("UP", tuple())
 
-        decimal_places_state = get_state_as_dict(xDecimalPlaces)
-        assert(decimal_places_state["Text"] == "3")
+            decimal_places_state = get_state_as_dict(xDecimalPlaces)
+            assert(decimal_places_state["Text"] == "3")
         
-        xDecimalPlaces.executeAction("DOWN", tuple())
+            xDecimalPlaces.executeAction("DOWN", tuple())
 
-        decimal_places_state = get_state_as_dict(xDecimalPlaces)
-        assert(decimal_places_state["Text"] == "2")
+            decimal_places_state = get_state_as_dict(xDecimalPlaces)
+            assert(decimal_places_state["Text"] == "2")
 
-        okBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(okBtn)
 
         self.ui_test.close_doc()
 
@@ -58,17 +52,14 @@ class SpinFieldTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog") as xCellsDlg:
         
-        xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
-        type_text(xDecimalPlaces, "4")
+            xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
+            type_text(xDecimalPlaces, "4")
 
-        decimal_places_state = get_state_as_dict(xDecimalPlaces)
-        assert(decimal_places_state["Text"] == "41")
+            decimal_places_state = get_state_as_dict(xDecimalPlaces)
+            assert(decimal_places_state["Text"] == "41")
 
-        okBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(okBtn)
 
         self.ui_test.close_doc()
 
diff --git a/uitest/demo_ui/tabdialog.py b/uitest/demo_ui/tabdialog.py
index 861b270989d9..bfa6129f06de 100644
--- a/uitest/demo_ui/tabdialog.py
+++ b/uitest/demo_ui/tabdialog.py
@@ -16,11 +16,8 @@ class TabDialogTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
-
-        xOkBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOkBtn)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog"):
+            pass
 
         self.ui_test.close_doc()
 
@@ -28,11 +25,8 @@ class TabDialogTest(UITestCase):
 
         self.ui_test.create_doc_in_start_center("calc")
 
-        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
-        xCellsDlg = self.xUITest.getTopFocusWindow()
-
-        xOkBtn = xCellsDlg.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOkBtn)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:FormatCellDialog"):
+            pass
 
         self.ui_test.close_doc()
 
diff --git a/uitest/impress_tests/backgrounds.py b/uitest/impress_tests/backgrounds.py
index 123c7ef81021..1ab001fea91f 100644
--- a/uitest/impress_tests/backgrounds.py
+++ b/uitest/impress_tests/backgrounds.py
@@ -113,33 +113,27 @@ class ImpressBackgrounds(UITestCase):
 
         buttons = ['btnbitmap', 'btncolor', 'btngradient', 'btnhatch', 'btnpattern']
         for index, button in enumerate(buttons):
-            self.ui_test.execute_dialog_through_command(".uno:PageSetup")
+            with self.ui_test.execute_dialog_through_command_guarded(".uno:PageSetup") as xPageSetupDlg:
 
-            xPageSetupDlg = self.xUITest.getTopFocusWindow()
-            tabcontrol = xPageSetupDlg.getChild("tabcontrol")
-            select_pos(tabcontrol, "1")
+                tabcontrol = xPageSetupDlg.getChild("tabcontrol")
+                select_pos(tabcontrol, "1")
 
-            xBtn = xPageSetupDlg.getChild(button)
-            xBtn.executeAction("CLICK", tuple())
+                xBtn = xPageSetupDlg.getChild(button)
+                xBtn.executeAction("CLICK", tuple())
 
-            # tdf#100024: Without the fix in place, this test would have crashed here
-            # changing the background to bitmap
-            xOkBtn = xPageSetupDlg.getChild("ok")
-            xOkBtn.executeAction("CLICK", tuple())
+                # tdf#100024: Without the fix in place, this test would have crashed here
+                # changing the background to bitmap
 
             self.checkDefaultBackground(button)
 
-            self.ui_test.execute_dialog_through_command(".uno:PageSetup")
+            with self.ui_test.execute_dialog_through_command_guarded(".uno:PageSetup") as xPageSetupDlg:
 
-            xPageSetupDlg = self.xUITest.getTopFocusWindow()
-            tabcontrol = xPageSetupDlg.getChild("tabcontrol")
-            select_pos(tabcontrol, "1")
+                tabcontrol = xPageSetupDlg.getChild("tabcontrol")
+                select_pos(tabcontrol, "1")
 
-            xBtn = xPageSetupDlg.getChild('btnnone')
-            xBtn.executeAction("CLICK", tuple())
+                xBtn = xPageSetupDlg.getChild('btnnone')
+                xBtn.executeAction("CLICK", tuple())
 
-            xOkBtn = xPageSetupDlg.getChild("ok")
-            xOkBtn.executeAction("CLICK", tuple())
 
             self.checkDefaultBackground('btnnone')
 
diff --git a/uitest/impress_tests/drawinglayer.py b/uitest/impress_tests/drawinglayer.py
index 7b33e369d2e6..ca09945aeaea 100644
--- a/uitest/impress_tests/drawinglayer.py
+++ b/uitest/impress_tests/drawinglayer.py
@@ -44,18 +44,12 @@ class ImpressDrawinglayerTest(UITestCase):
         xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
         self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
 
-        self.ui_test.execute_dialog_through_command(".uno:Size")
-
-        xDialog = self.xUITest.getTopFocusWindow()
-
-        self.assertEqual('25.2', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
-        self.assertEqual('9.13', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
-        self.assertEqual('2.4', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
-        self.assertEqual('4.69', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
-        self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
-
-        xOK = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOK)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:Size") as xDialog:
+            self.assertEqual('25.2', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
+            self.assertEqual('9.13', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
+            self.assertEqual('2.4', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
+            self.assertEqual('4.69', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
+            self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
 
         self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
         xEditWin.executeAction("DESELECT", tuple())
@@ -95,18 +89,12 @@ class ImpressDrawinglayerTest(UITestCase):
         xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
         self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
 
-        self.ui_test.execute_dialog_through_command(".uno:Size")
-
-        xDialog = self.xUITest.getTopFocusWindow()
-
-        self.assertEqual('12.6', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
-        self.assertEqual('4.57', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
-        self.assertEqual('0.95', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
-        self.assertEqual('3.84', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
-        self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
-
-        xOK = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOK)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:Size") as xDialog:
+            self.assertEqual('12.6', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
+            self.assertEqual('4.57', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
+            self.assertEqual('0.95', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
+            self.assertEqual('3.84', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
+            self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
 
         self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
         xEditWin.executeAction("DESELECT", tuple())
@@ -146,14 +134,8 @@ class ImpressDrawinglayerTest(UITestCase):
         xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
         self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
 
-        self.ui_test.execute_dialog_through_command(".uno:Size")
-
-        xDialog = self.xUITest.getTopFocusWindow()
-
-        self.assertEqual('30', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
-
-        xOK = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOK)
+        with self.ui_test.execute_dialog_through_command_guarded(".uno:Size") as xDialog:
+            self.assertEqual('30', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
 
         self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
         xEditWin.executeAction("DESELECT", tuple())
diff --git a/uitest/uitest/uihelper/common.py b/uitest/uitest/uihelper/common.py
index 0ce04dbe780a..726905bee28c 100644
--- a/uitest/uitest/uihelper/common.py
+++ b/uitest/uitest/uihelper/common.py
@@ -28,37 +28,32 @@ def get_url_for_data_file(file_name):
     return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
 
 def change_measurement_unit(UITestCase, unit):
-    UITestCase.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")
-    xDialogOpt = UITestCase.xUITest.getTopFocusWindow()
-
-    xPages = xDialogOpt.getChild("pages")
-    xAppEntry = xPages.getChild('3')
-    xAppEntry.executeAction("EXPAND", tuple())
-    xGeneralEntry = xAppEntry.getChild('0')
-    xGeneralEntry.executeAction("SELECT", tuple())
-
-    # Calc
-    if 'unitlb' in xDialogOpt.getChildren():
-        xUnit = xDialogOpt.getChild("unitlb")
-
-    # Writer
-    elif 'metric' in xDialogOpt.getChildren():
-        xUnit = xDialogOpt.getChild("metric")
-
-    # Impress
-    elif 'units' in xDialogOpt.getChildren():
-        xUnit = xDialogOpt.getChild("units")
-
-    props = {"TEXT": unit}
-    actionProps = mkPropertyValues(props)
-    xUnit.executeAction("SELECT", actionProps)
-
-    # tdf#137930: Check apply button doesn't reset the value
-    xApplyBtn = xDialogOpt.getChild("apply")
-    xApplyBtn.executeAction("CLICK", tuple())
-    UITestCase.assertEqual(unit, get_state_as_dict(xUnit)['SelectEntryText'])
-
-    xOKBtn = xDialogOpt.getChild("ok")
-    UITestCase.ui_test.close_dialog_through_button(xOKBtn)
+    with UITestCase.ui_test.execute_dialog_through_command_guarded(".uno:OptionsTreeDialog") as xDialogOpt:
+        xPages = xDialogOpt.getChild("pages")
+        xAppEntry = xPages.getChild('3')
+        xAppEntry.executeAction("EXPAND", tuple())
+        xGeneralEntry = xAppEntry.getChild('0')
+        xGeneralEntry.executeAction("SELECT", tuple())
+
+        # Calc
+        if 'unitlb' in xDialogOpt.getChildren():
+            xUnit = xDialogOpt.getChild("unitlb")
+
+        # Writer
+        elif 'metric' in xDialogOpt.getChildren():
+            xUnit = xDialogOpt.getChild("metric")
+
+        # Impress
+        elif 'units' in xDialogOpt.getChildren():
+            xUnit = xDialogOpt.getChild("units")
+
+        props = {"TEXT": unit}
+        actionProps = mkPropertyValues(props)
+        xUnit.executeAction("SELECT", actionProps)
+
+        # tdf#137930: Check apply button doesn't reset the value
+        xApplyBtn = xDialogOpt.getChild("apply")
+        xApplyBtn.executeAction("CLICK", tuple())
+        UITestCase.assertEqual(unit, get_state_as_dict(xUnit)['SelectEntryText'])
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/uitest/uihelper/testDialog.py b/uitest/uitest/uihelper/testDialog.py
index 43f0a5bc0794..9b63159c6148 100644
--- a/uitest/uitest/uihelper/testDialog.py
+++ b/uitest/uitest/uihelper/testDialog.py
@@ -13,27 +13,21 @@ from uitest.uihelper.common import get_state_as_dict
 # the test only checks if LibreOffice crashes by opening the dialog
 def testDialog(UITestCase, app, dialog):
     doc = UITestCase.ui_test.create_doc_in_start_center(app)
-    UITestCase.ui_test.execute_dialog_through_command(dialog['command'])
-    xDialog = UITestCase.xUITest.getTopFocusWindow()
-
-    xCloseBtn = xDialog.getChild(dialog['closeButton'])
-    if 'skipTestOK' in dialog and dialog['skipTestOK'] == True:
-        xOKBtn = None
-    else:
-        try:
-            xOKBtn = xDialog.getChild("ok")
-            if (get_state_as_dict(xOKBtn)["Enabled"] != "true"):
-                xOKBtn = None
-        except:
+    with UITestCase.ui_test.execute_dialog_through_command_guarded(dialog['command'], close_button=dialog['closeButton']) as xDialog:
+        if 'skipTestOK' in dialog and dialog['skipTestOK'] == True:
             xOKBtn = None
+        else:
+            try:
+                xOKBtn = xDialog.getChild("ok")
+                if (get_state_as_dict(xOKBtn)["Enabled"] != "true"):
+                    xOKBtn = None
+            except:
+                xOKBtn = None
 
-    UITestCase.ui_test.close_dialog_through_button(xCloseBtn)
     if (xOKBtn != None):
         print("check also OK button")
-        UITestCase.ui_test.execute_dialog_through_command(dialog['command'])
-        xDialog = UITestCase.xUITest.getTopFocusWindow()
-        xOKBtn = xDialog.getChild("ok")
-        UITestCase.ui_test.close_dialog_through_button(xOKBtn)
+        with UITestCase.ui_test.execute_dialog_through_command_guarded(dialog['command']):
+            pass
     UITestCase.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list